Questions tagged [ecmascript-5]

ECMAScript is the name of the Ecma International Standard 262. It is based on the scripting language JavaScript which was delivered by Netscape to Ecma for standardization. The 5th Edition is an update of the 3rd edition specification after the cancellation of the 4th edition. It adds new features including strict mode, getters and setters, a JSON object, and new methods for Object, Array, Date, and Function prototypes.

In 1995 Brendan Eich of Netscape invented a scripting language JavaScript for the Netscape browser. One year later Microsoft developed a compatible dialect of the language, JScript. Lately flash platform implemented its ActionScript language based in the same standard.

Netscape delivered JavaScript to Ecma International for standardization which started the process as EcmaScript in the Ecma-262 Standard in November 1996(5).

ECMAScript-5 is an update of the EMCAScript-262 3rd edition specification after the cancellation of the 4th edition. It adds new features including strict mode, getters and setters, a JSON object, and new methods for Object, Array, Date, and Function prototypes.

Articles covering the new specification in detail are available e.g. on infoq.com and the Opera Dev Channel.

This compatibility table covers the Browser support of EcmaScript 5.

References:

  1. JavaScript Wikipedia Article
  2. EcmaScript Wikipedia Article
  3. Ecma International Website
  4. Ecma-262 Specification
  5. Press Release of Javascript Standardization
  6. EcmaScipt Edition 5 - HTML Version
  7. EcmaScript Edition 3 - PDF Version
1857 questions
1659
votes
19 answers

What is the purpose of the var keyword and when should I use it (or omit it)?

NOTE: This question was asked from the viewpoint of ECMAScript version 3 or 5. The answers might become outdated with the introduction of new features in the release of ECMAScript 6. What exactly is the function of the var keyword in JavaScript,…
Alex
  • 75,813
  • 86
  • 255
  • 348
516
votes
13 answers

how to stop Javascript forEach?

I'm playing with Node.js and Mongoose — trying to find specific comment in deep comments nesting with recursive function and forEach within. Is there a way to stop Node.js forEach? As I understand every forEach iteration is a function and and I…
kulebyashik
  • 5,359
  • 4
  • 18
  • 13
492
votes
8 answers

Get array of object's keys

I would like to get the keys of a JavaScript object as an array, either in jQuery or pure JavaScript. Is there a less verbose way than this? var foo = { 'alpha' : 'puffin', 'beta' : 'beagle' }; var keys = []; for (var key in foo) { …
Richard
  • 31,629
  • 29
  • 108
  • 145
207
votes
10 answers

Difference between freeze and seal

I just heard about the JavaScript methods freeze and seal, which can be used to make any Object immutable. Here's a short example how to use it: var o1 = {}, o2 = {}; Object.freeze(o2); o1["a"] = "worked"; o2["a"] = "worked"; alert(o1["a"]); …
maja
  • 17,250
  • 17
  • 82
  • 125
160
votes
14 answers

What does [].forEach.call() do in JavaScript?

I was looking at some snippets of code, and I found multiple elements calling a function over a node list with a forEach applied to an empty array. For example I have something like: [].forEach.call( document.querySelectorAll('a'), function(el) { …
Mimo
  • 6,015
  • 6
  • 36
  • 46
155
votes
9 answers

How to implement private method in ES6 class with Traceur

I use Traceur Compiler to have advantage with ES6 features now. I want to implement this stuff from ES5: function Animal() { var self = this, sayHi; sayHi = function() { self.hi(); }; this.hi = function() {/* ...…
Boris Zagoruiko
  • 12,705
  • 15
  • 47
  • 79
155
votes
4 answers

Javascript Reduce an empty array

When I reduce the array, I am trying to get the number zero, but I dont clearly understand the behaviour of the function [].reduce(function(previousValue, currentValue){ return Number(previousValue) + Number(currentValue); }); result TypeError:…
agusgambina
  • 6,229
  • 14
  • 54
  • 94
147
votes
28 answers

Dynamically set property of nested object

I have an object that could be any number of levels deep and could have any existing properties. For example: var obj = { db: { mongodb: { host: 'localhost' } } }; On that I would like to set (or overwrite)…
John B.
  • 2,309
  • 5
  • 23
  • 22
131
votes
4 answers

Creating range in JavaScript - strange syntax

I've run into the following code in the es-discuss mailing list: Array.apply(null, { length: 5 }).map(Number.call, Number); This produces [0, 1, 2, 3, 4] Why is this the result of the code? What's happening here?
Benjamin Gruenbaum
  • 270,886
  • 87
  • 504
  • 504
115
votes
7 answers

Why are Objects not Iterable in JavaScript?

Why are objects not iterable by default? I see questions all the time related to iterating objects, the common solution being to iterate over an object's properties and accessing the values within an object that way. This seems so common that it…
boombox
  • 2,396
  • 2
  • 11
  • 15
108
votes
21 answers

Accessors are only available when targeting ECMAScript 5 and higher

I am trying to run this code, but it is giving me the following errors: Animal.ts(10,13): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. Animal.ts(14,13): error TS1056: Accessors are only available when targeting…
jagdish khetre
  • 1,381
  • 2
  • 8
  • 15
96
votes
7 answers

Is there any way to check if strict mode is enforced?

Is there anyway to check if strict mode 'use strict' is enforced , and we want to execute different code for strict mode and other code for non-strict mode. Looking for function like isStrictMode();//boolean
Deepak Patil
  • 3,419
  • 3
  • 25
  • 22
91
votes
7 answers

Any performance benefit to "locking down" JavaScript objects?

JavaScript 1.8.5 (ECMAScript 5) adds some interesting methods that prevent future modifications of a passed object, with varying degrees of thoroughness: Object.preventExtensions(obj) Object.seal(obj) Object.freeze(obj) Presumably the main point…
callum
  • 34,206
  • 35
  • 106
  • 163
87
votes
3 answers

Can I disable ECMAscript strict mode for specific functions?

I don't find anything about my question here on MDC or the ECMAscript specifications. Probably somebody knows a more 'hacky' way to solve this. I'm calling "use strict" on every javascript file in my environment. All my files start like…
jAndy
  • 231,737
  • 57
  • 305
  • 359
78
votes
1 answer

Why is 019 not a JavaScript syntax error? Or why is 019 > 020

If I type 019 > 020 in the JavaScript console (tested in both Chrome and Firefox), I get the answer true. This is due to 020 being interpreted as an OctalIntegerLiteral (equals 16) whereas 019 is apparently being interpreted as DecimalLiteral (and…
lexicore
  • 42,748
  • 17
  • 132
  • 221
1
2 3
99 100