What does the line 'use strict' at the top of the code block mean? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 12

What does the line 'use strict' at the top of the code block mean?

29th Jul 2019, 6:10 AM
Vukan✔
Vukan✔ - avatar
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.
30th Jul 2019, 9:06 PM
Fredericks
Fredericks - avatar
+ 9
Defines that JavaScript code should be executed in "strict mode". More: https://www.w3schools.com/js/js_strict.asp
29th Jul 2019, 6:17 AM
renamed
renamed - avatar
+ 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. 👍😉
29th Jul 2019, 2:47 PM
Vukan✔
Vukan✔ - avatar
+ 5
i don't really know much, but i think, - it kinda changes how you would use variables - STRICT (literally)
29th Jul 2019, 6:20 AM
Ginfio
Ginfio - avatar
+ 5
rules should be strictly followed
30th Jul 2019, 12:13 PM
Ayushi Gujarati
Ayushi Gujarati - avatar
+ 2
you can to make app sonic
30th Jul 2019, 8:40 AM
Khadijah
Khadijah - avatar