Skip to content

Latest commit

 

History

History
42 lines (25 loc) · 1.19 KB

File metadata and controls

42 lines (25 loc) · 1.19 KB

Appendix B - Strict Mode

Strict mode is something you can enable in your JavaScript code. Running your code in strict mode will result in a slightly different interpretation of the language. Strict mode is described as a more "modern version" of JavaScript that is less prone to errors.

Not running your code in strict mode is sometimes referred to as "Sloppy mode".

Strict vs sloppy mode goofy image

When is my code running in strict mode?

One way is to put a “use strict” statement at the top of a file.

"use strict"

console.log("This is running in strict mode!")

It can also be enabled for an individual function.

function func() {
	"use strict"
	console.log("This is running in strict mode!")
}

Strict mode is also auto-enabled for all ES modules. You are using ES modules if you use the import/export keywords.

import {} from "./example"

console.log("This is running in strict mode!")

export {}

Example of difference

An example can be found in chapter 6 "Traditional function on its own".