Strict mode in javascript

Strict mode in javascript
0

#1

Ive seen these two paragraphs of code on YDKJS up and going.
If I understand them wrongly ,please tell me.

1st:

function foo() {
	"use strict";

	// this code is strict mode

	function bar() {
		// this code is strict mode
	}
}

// this code is not strict mode

In the code above, everything under function foo() is under strict mode.

2nd:

"use strict";

function foo() {
	// this code is strict mode

	function bar() {
		// this code is strict mode
	}
}

// this code is strict mode

In the code above, everything is in strict mode.

Am I right about this???


#2

Yes, I think you got it right. Far as I know strict runs in its “block”. Anyway, it’s recommended to use the 2nd one so you don’t have to switch back and forth


#3

I see. So I just write everything in strict mode then I am golden?


#4

Just put it at the very top of the js file or very start of your code - before anything else and you should be golden. Strict makes for good habits.


#5

Thanks!!!

(this 20 character limit omg… killme)