Nodejs need to use "strict use"? or what is node strict mode best practice?

I am new to node.js and javascript.I checked the node.js code examples and used use strict mode.

For example, server.js:

 'use strict'; //some server code 

In addition, I found out that use strict present at the head of each js file. This confused me, and so I want to know what is best used in Nodejs to use strict mode?


Thanks to everyone, my question is focused on strict mode. In this mode, you can report some code error. Does the back-end also have a strict bug reporter? And if I need to use it, should I add it to every js file header? Or add it to the main file (server.js or etc.)? Or use your own node.js style?

+7
javascript
source share
3 answers

Use it always. If nothing else, this ensures that your code is written correctly and is compatible with the browser as it may be. It will also reveal mundane syntax errors that would otherwise remain unreasonable and lead to hours of unnecessary debugging.

+6
source share

"use strict" is a behavior flag that you can add to the first line of any JavaScript file or function. This leads to errors when some bad methods are used in your code, and prohibits the use of certain functions, for example, with.

Literature:

+3
source share

Nodejs is server-side javascript, so many coding methods are the same in both. Therefore, the use of strict mode is common.

This ensures that you do not violate certain coding rules, such as undeclared variables x=14; , the use of the names of certain variables arguments,eval , which are the names of several global variables and functions.

+1
source share

All Articles