Cole
Cole

Reputation: 441

Why is strict mode's activator 'use strict' a string?

Not to be confused with wanting to know how use strict works, but why is strict mode activated with 'use strict'; or "use strict"; as opposed to an expression like use strict;?

Upvotes: 5

Views: 70

Answers (2)

Taufik Nur Rahmanda
Taufik Nur Rahmanda

Reputation: 1969

I think the answer is simple. As we know, ECMAScript a.k.a javascript is not standarized until now. So why string? It's because all browsers agree to use 'use strict' as more preferable than use strict. It also to prevent error on older browser which is not support strict mode.

Upvotes: -1

Quentin
Quentin

Reputation: 943585

use strict; would throw an error in JS engines that did not support strict mode.

Using a string is backwards compatible.

Upvotes: 11

Related Questions