+ 12
What does the line 'use strict' at the top of the code block mean?
7 Answers
+ 6
Javascript is a loosely typed language, but in order not to get too sloppy, strict mode was introduced.
It's usefulness is perhaps best seen in variable declaration, in that, it requires you to "expressly" define a variable instead of the implied mannerism most of us JS coders are "comfortable" with.
e.g. for(i = 0; i < 10; i++){
console.log(i);
}
The above code ordinarily will work fine in a non-strict mode but in the strict mode, it will not work.
Because, as I said earlier, you'll have to declare:
var i;
for(i= 0; i < 10; i++){}
OR
for(var i = 0; i < 10; i++){}
Also, đVukanđ has another example of what strict mode help you avoid.
+ 9
Defines that JavaScript code should be executed in "strict mode".
More: https://www.w3schools.com/js/js_strict.asp
+ 7
ES5 describes a special version of JavaScript, called strict mode (strict mode). In strict mode, the use of ambiguous constructs from earlier versions of the language causes errors instead of leading to unplanned behavior.
function strictFunction() {
 'use strict'; Â
myVar = 4; //ReferenceError }
In the code snippet above, we are trying to assign a value to an undeclared variable. Outside of strict mode, the execution of such a command will result in the addition of the variable myVar to the global scope, which, if you do not pay enough attention to such things, can completely change the functionality of the script. In strict mode, this results in an error message, and thus prevents a possible disruption in the functioning of the program.
The ES2015 modules use strict default mode, but in closures created using functions, the 'use strict' command can be used at the function level, as well as at the entire file level.
đđ
+ 5
i don't really know much, but i think,
- it kinda changes how you would use variables
- STRICT (literally)
+ 5
rules should be strictly followed
+ 2
you can to make app sonic