What does “use strict” do in JavaScript, and what is the reasoning behind it?

前端 未结 28 3076
半阙折子戏
半阙折子戏 2020-11-21 06:05

Recently, I ran some of my JavaScript code through Crockford\'s JSLint, and it gave the following error:

Problem at line 1 character 1: Missing \"use

28条回答
  •  臣服心动
    2020-11-21 06:33

    Normally, JavaScript does not follow strict rules, hence increasing chances of errors. After using "use strict", the JavaScript code should follow strict set of rules as in other programming languages such as use of terminators, declaration before initialization, etc.

    If "use strict" is used, the code should be written by following a strict set of rules, hence decreasing the chances of errors and ambiguities.

提交回复
热议问题