标签云

微信群

扫码加入我们

WeChat QR Code

是怎样的

This question already has an answer here:

I have started to explore the Node.js and wrote many demo web application, to understand the flow of Node.js, Express.js, jade, etc..

But one thing I came across recently, is the statement "use strict" as the first line inside every function and every .js file.

How exactly is it is interpreted by Node.js?


A 'use strict'; string before any statement of a function will put it in strict mode.

2018年06月18日09分26秒

GoloRoden though I refrain from using it file-wide, MDN says it works as intended when setting 'use strict'; file-wide. Problems arise when you concatenate non-strict with strict files, or when you set use strict inside an HTML page's inline script tag (which Node does not have).

2018年06月19日09分26秒

GoloRoden: Is it a no-go? Chrome behaves exactly the same way as node here.

2018年06月19日09分26秒

Eric: Thanks, Chrome behaves exactly the same way as node here.. since V8 is the interpreter.. ;)

2018年06月19日09分26秒

Mohit Pandey: Fact is I referred stack overflow for learning node.js . I referred this link: stackoverflow.com/questions/2353818/…. So registered and asked this questions.. love the way people commented and answered so quickly... thanks to all.....

2018年06月18日09分26秒

Why is this answer downvoted without any comment?

2018年06月18日09分26秒

First of all, Chrome is not the only browser on the planet. Just that Node.js and Chrome use V8, does not mean neccessarily that it works the same in all browsers. Second, there is a difference in the way, files (aka modules) are loaded. Third, scripts for browsers get usually concatenated for production use, and that's where problems may arise when you just say that both are the same environments. They're not. V8 is not the only important thing when it comes to executing Node.js files.

2018年06月19日09分26秒

GabrielLlamas: Thanks. Golo Roden: Yes, if commented properly. we can give more better answers.

2018年06月19日09分26秒

AmolMKulkarni : "Module code is always strict mode code" - it is not exactly true for Node. If you will not use 'use strict' in node v.6.10.2 following code will not throw error: var obj = {}; Object.preventExtensions(obj); obj.a=1;

2018年06月18日09分26秒

This could be helpful research about default strict mode: imaginativethinking.ca/…

2018年06月19日09分26秒