Questions tagged [use-strict]

According to Mozilla Developer Network, ECMAScript 5's strict mode is a way to opt in to a restricted variant of JavaScript. Strict mode isn't just a subset: it intentionally has different semantics from normal code.

According to Mozilla Developer Network, ECMAScript 5's strict mode is a way to opt in to a restricted variant of JavaScript. Strict mode isn't just a subset: it intentionally has different semantics from normal code.

100 questions
6
votes
3 answers

Javascript: besides "use strict", which other "use" directives are there?

Besides use strict, which other use directives are there?
fbas
  • 1,676
  • 3
  • 16
  • 26
6
votes
1 answer

JS: What is 'this' coercion? What does use-strict have to do with that?

I read the following on a website: Use-strict has an advantage. It eliminates this coercion. Without strict mode, a reference to a this value of null or undefined is automatically coerced to the global. This can cause many headfakes and …
Sunny Bharadwaj
  • 153
  • 1
  • 11
6
votes
2 answers

Weird behaviour with 'use strict' and read only properties

On the MDN strict mode reference page it says Any assignment that silently fails in normal code (assignment to a non-writable property, assignment to a getter-only property, assignment to a new property on a non-extensible object) will throw in…
tleef
  • 3,516
  • 1
  • 24
  • 34
6
votes
1 answer

Does "use strict" in the constructor extend to prototype methods?

I'm trying to figure out whether the definition of 'use strict' extends to the prototype methods of the constructor. Example: var MyNamespace = MyNamespace || {}; MyNamespace.Page = function() { "use strict"; }; MyNamespace.Page.prototype =…
Spencer Mark
  • 5,263
  • 9
  • 29
  • 58
6
votes
2 answers

Use the || operator notice

Javascript code: var a = (b) ? b : 40; It is working, just NetBeans says: "Use the || operator (Column [where the ? is])". I didn't find any explanation. What is it? Thanks!
Gábor Varga
  • 840
  • 5
  • 15
  • 25
5
votes
1 answer

Assignment to read-only properties is not allowed in strict mode IE11

I have been told by IE11 that var self = this is a read-only variable... Yet I am not assigning anything to it after its declaration point. The only variable is height that is changing. Even though, i would be able to change it when using var 'use…
Jamie Hutber
  • 26,790
  • 46
  • 179
  • 291
5
votes
3 answers

"use strict"; + jQuery.getScript() = script can't export to global namespace

Suppose I have the following script, called include_strict.js. After it executes I should have window.global1 defined: "use strict"; var globalVar = {}; alert(typeof window.globalVar); But if I include it from a block of javascript…
mxxk
  • 9,514
  • 5
  • 38
  • 46
4
votes
1 answer

How to count the number of arguments to a JavaScript function without using "arguments"?

I've been updating a library I wrote some time ago, and in doing so have realized that there are unexpected errors when testing in strict mode. These arise because of checks at the beginning of some of the API functions which throw an error if there…
Sophie
  • 461
  • 1
  • 4
  • 12
4
votes
2 answers

"use strict" in the middle of the program

Why the second function didn't use the "use strict"; mode (it shows me window object in console): function test() { console.log(this); } test(); // will be global or window, it's okay "use strict"; function test2() { …
Avernikoz
  • 463
  • 2
  • 5
  • 15
4
votes
1 answer

Javascript use strict error not catching

I am creating a backbone.js app that uses require.js for AMD. In order to check for use strict support in the browser, I have included the following code. However, when the code is run, the error thrown by var o = {p:1, P:2} is not caught as I…
4
votes
2 answers

Javascript: prototype method error?

I am getting a "TestFunc is not defined" error when this bit of code... /* my_object.js */ "use strict"; function MyObject (param) { this.param = param; } MyObject.prototype.TestFunc = function () { console.log ('in…
user35288
4
votes
1 answer

"Function declarations cannot be nested inside a statement" - IE in strict mode error

In a "use strict" application, I'm using document.createTreeWalker to traverse a DOM tree. After I get the tree from the browser I use a while loop to push the values into an array. The code is an upgrade to the excellent Letteringjs.com plugin, and…
pilau
  • 6,635
  • 4
  • 56
  • 69
3
votes
1 answer

With "use strict" enabled, why can I assign a variable without let while using prompt()

I wrote "use strict"; at the top of my script. I can't write num = 5; because I get ReferenceError: Can't find variable: num. To fix this I can write let num = 5;. Using that logic, why am I allowed to write name = prompt("What is your…
Brian
  • 823
  • 6
  • 14
3
votes
2 answers

Why does strict mode make such simple actions such different?

There is an extremely simple algorythm, which works surprisely different in two cases, depending on the presence of "use strict". Case 1: If func() declaration is within the strict mode, than console logs primitive "use strict"; // strict mode is…
Parzh from Ukraine
  • 7,999
  • 3
  • 34
  • 65
3
votes
0 answers

"Use Strict" and the applicable scope

I am interested to learn when using strict mode, where does it apply to. I know that I cannot put it once in my file and be done, rather it has to be in the functions, etc. I was told if I put it in an IIFE then I am good, but my questions becomes…
stoXe
  • 313
  • 6
  • 13