+ 21

What does 'use strict' mean in Javascript?

JS 'use strict' meaning

17th Oct 2018, 12:40 PM
Sonic
Sonic - avatar
11 Answers
+ 16
TurtleShell in that case why is there even a non-strict or lenient mode? Will strict mode be the default in the future?
17th Oct 2018, 12:50 PM
Sonic
Sonic - avatar
+ 12
My opinion: It's nice to see because it makes devs declare variables (even guarding against redeclaration) instead of depending on JS auto-creating globals + hoisting. Related functionality: It enables 'let', 'const', `template` literals, classes + other things for my embedded webview (+ other people's too). * Without it, many of the popular animations here are black on black, not-as-intended or don't work at all. ~ They don't necessarily show errors, but I have to guess if what I see / don't see might be JS compatibility bugs. * Then when adding 'use strict' I often must correct declarations, but eventually I can test the code and comment. As you might imagine, I don't like to 'add it later' quite as much. It really ought to be there from the start.
17th Oct 2018, 3:32 PM
Kirk Schafer
Kirk Schafer - avatar
+ 10
Thanks all for your answers. 👍
18th Oct 2018, 4:55 AM
Sonic
Sonic - avatar
+ 6
Sonic because a lot of new and old code would be broken, you have to remember that JS powers probably around 95% of websites. As you probably also noticed "use strict"; is a string which wont cause errors on really old browsers.
17th Oct 2018, 12:56 PM
TurtleShell
TurtleShell - avatar
+ 5
Strict mode changes some previously-accepted mistakes into errors. JavaScript was designed to be easy for novice developers, and sometimes it gives operations which should be errors non-error semantics. Sometimes this fixes the immediate problem, but sometimes this creates worse problems in the future. First, strict mode makes it impossible to accidentally create global variables. Second, strict mode makes assignments which would otherwise silently fail to throw an exception. For example, NaN is a non-writable global variable. In normal code assigning to NaN does nothing; the developer receives no failure feedback. In strict mode assigning to NaN throws an exception. Any assignment that silently fails in normal code (assignment to a non-writable global or property, assignment to a getter-only property, assignment to a new property on a non-extensible object) will throw in strict mode:
18th Oct 2018, 5:44 AM
🎈Amit💌
🎈Amit💌 - avatar
+ 4
http://lucybain.com/blog/2014/js-use-strict/ It basically puts your code in strict mode which forces you to write better code.
17th Oct 2018, 12:44 PM
TurtleShell
TurtleShell - avatar
+ 4
https://www.w3schools.com/js/js_strict.asp A good tutorial by w3 schools
17th Oct 2018, 2:37 PM
Seniru
Seniru - avatar
+ 2
'use strict' mode is very important concept in javascript. if you are using it, it dosen't allow this as window keyword in your code unless you bind it.It actually make your code more secured because in non strict mode third person can easily access to your code because in non strict mode all your function variable get store in window.For example you make quiz application in non strict mode then user can easily access timer and he/she can make changes.I hope you will understand ,if still you have doubt text again. Thanks
18th Oct 2018, 4:51 AM
BalGovind
BalGovind - avatar
+ 2
Strict mode in JavaScript. Strict Mode is a new feature in ECMAScript 5 that allows you to place a program, or a function, in a “strict” operating context. ... The statement “use strict”; instructs the browser to use the Strict mode, which is a reduced and safer feature set of JavaScript. https://crbtech.in/java-training/java-certification-path-certified-made-easy/
18th Oct 2018, 4:54 AM
meenal deshpande
+ 1
Strict mode in JavaScript. Strict Mode is a new feature in ECMAScript 5 that allows you to place a program, or a function, in a “strict” operating context. This strict context prevents certain actions from being taken and throws more exceptions. https://www.geeksforgeeks.org/strict-mode-javascript/ https://www.w3schools.com/js/js_strict.asp
19th Oct 2018, 10:25 AM
deepak sharma
deepak sharma - avatar