Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"use strict"; now allows duplicated properties?

I just found that in the last Chrome 42 and FF 37.0.2 this lines of code are perfectly legal

"use strict";
var o = { p: 1, p: 2 };

(copy-pasted from MDN )

In IE 10-11 and Opera 28.0.1750 it throws error as expected.

In the same time,

abc=0;

causes error (undeclared variable) as expected.

Does anybody know what caused such change?

like image 358
Andrey Kuleshov Avatar asked Apr 29 '15 07:04

Andrey Kuleshov


People also ask

What are the effects of having use strict?

The "use strict" Directive It is not a statement, but a literal expression, ignored by earlier versions of JavaScript. The purpose of "use strict" is to indicate that the code should be executed in "strict mode". With strict mode, you can not, for example, use undeclared variables.

What are the advantages and disadvantages of using use strict?

what are the advantages and disadvantages to using it? If you put "use strict"; at the top of your code (or function), then the JS is evaluated in strict mode. Strict mode throws more errors and disables some features in an effort to make your code more robust, readable, and accurate.

Why do we use strict mode in JavaScript?

Strict mode changes some previously-accepted mistakes into errors. JavaScript was designed to be easy for novice developers, and sometimes it gives operations which should be errors non-error semantics. Sometimes this fixes the immediate problem, but sometimes this creates worse problems in the future.

What is correct way to run a JavaScript in strict mode?

Using Strict mode for a function: Likewise, to invoke strict mode for a function, put the exact statement “use strict”; (or 'use strict';) in the function's body before any other statements. Examples of using Strict mode: Example: In normal JavaScript, mistyping a variable name creates a new global variable.


1 Answers

There is a Bugzilla ticket here. From what I gather (here and other pages I have looked up), duplicate properties are legal in ECMAScript version 6, opposed to ES5, where it is forbidden in strict mode.

like image 77
meskobalazs Avatar answered Sep 24 '22 01:09

meskobalazs