“use strict”;

Andrew Park
2 min readApr 18, 2021

As a new JavaScript programmer, I will take any help I can get to avoid writing sloppy code. One of those help comes with ECMAScript 5. Strict mode will throw error messages for certain mistakes.

To apply strict mode to entire script, start the script with “use strict”.

One error that I make quite often is to use a variable that has not been declared. Without strict mode, javaScript will continue to run even the variable has not been declared:

In the below (without strict mode), I can set values to variables (num1, num2 and total) that have not been defined, and javaScript is happy to continue with the calculation.

However, with strict mode enabled, javaScript will throw below error:

Once I declare the variables, then javaScript will continue with calculation.

Another nice feature of strict mode is it prevents declaring keywords for future JavaScript releases. They are: implements, interface, let, package, private, protected, public, static, yield.

Without strict mode, I could use any one of above keywords as a variable:

However, strict mode will throw an error:

For new javaScript programmers, I think strict mode is a must since it can guide you with writing clean code. Why not use the feature if it is there to help you to become a better programmer.

--

--