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”]); //prints “worked” alert(o2[“a”]); //prints “undefined” What is the difference between freeze and seal? … Read more

how to stop Javascript forEach? [duplicate]

This question already has answers here: Short circuit Array.forEach like calling break (30 answers) Closed 4 years ago. 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 … Read more

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, and what is the difference between var someNumber = 2; var someFunction = … Read more