简体   繁体   中英

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

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

Using a string is backwards compatible.

I think the answer is simple. As we know, ECMAScript aka 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM