DEV Community

Cover image for JavaScript `use strict` Explained in 2 Minutes

JavaScript `use strict` Explained in 2 Minutes

Gabe Romualdo on January 17, 2020

JavaScript is a very lenient language in terms of how it is interpreted. For example: x = 5; Enter fullscreen mode Exit fullsc...
Collapse
 
ankitbeniwal profile image
Ankit Beniwal • Edited

Also, 'use strict' prevents variable/object hoisting i.e. JavaScript in strict mode does not allow variables to be used if they are not declared.

Best practice is to move the variable declarations to the top of the script.

Collapse
 
gaberomualdo profile image
Gabe Romualdo • Edited

Good point, thank you for commenting!

— Gabriel

Collapse
 
piperymary profile image
Mary

Hey there! I really appreciate your blog, it's full of interesting and useful information. I also wrote an article about use strict in my blog, there's also some code lines that can be useful.

Collapse
 
andreandyp profile image
André Michel Andy

JavaScript allows octal numbers in ES6+ but only with the correct notation:

"use strict";
var x = 010; // this throws an error
var y = 0o10; // but this doesn't
Collapse
 
gaberomualdo profile image
Gabe Romualdo • Edited

Good point, thanks for commenting!

— Gabriel

Collapse
 
sonicoder profile image
Gábor Soós

Strict mode is on by default for Ecmascript Modules. Projects built with Babel/Typescript doesn't require it, only Node projects.