Strict mode in javascript

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???

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

1 Like

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

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.

1 Like

Thanks!!!

(this 20 character limit omg… killme)