JavaScript is specified by ECMAScript, and modern engines use parsing, JIT compilation, and optimization rather than pure line-by-line interpretation.
- ECMAScript is the language standard
- Engines implement the spec
- Modern engines optimize hot code paths
JavaScript supports several loop forms, plus iterator and generator protocols for custom iteration behavior.
- `for...of` iterates values
- `for...in` iterates enumerable property keys
- Generators pause and resume with `yield`
Arrays are ordered list-like objects with mutation helpers like `push`, `pop`, `shift`, and `unshift`.
- Array methods mix mutation and non-mutation
- Front operations are typically costlier than tail operations
- Arrays are objects under the hood
Strong JavaScript code emphasizes readability, safe defaults, modular design, clear errors, and predictable state changes.
- Prefer `const` unless reassignment is needed
- Avoid accidental globals and hidden mutation
- Good names and modules reduce cognitive load
JavaScript has primitive values like numbers and strings plus reference types like objects and arrays, and some runtime quirks like `typeof null` and `NaN`.
- Primitives copy by value
- Objects and arrays compare by reference
- `NaN` is a special number value
JavaScript is a high-level language used in browsers and servers, and it is dynamically and weakly typed.
- Runs in browsers and Node.js
- Types are checked at runtime
- Coercion happens more freely than in strongly typed languages
Client-side JavaScript can create security issues when it injects unsafe content, trusts the wrong source, or executes arbitrary code.
- Unsafe HTML updates can cause XSS
- CSRF abuses trusted browser state
- `eval` is dangerous and usually unnecessary
Strings are immutable primitive values, and JavaScript offers many helper methods plus template literals for interpolation.
- Methods return new strings
- Template literals support interpolation
- Immutability means characters are not changed in place
JSON is a text format for structured data, and JavaScript uses `JSON.parse` to read it and `JSON.stringify` to serialize it.
- JSON is text, not live objects
- Parsing turns text into values
- Stringifying is common for APIs and storage
Modern JavaScript uses modules to organize code, with ES modules in the language standard and CommonJS still common in older Node.js code.
- Named and default exports behave differently
- ES modules use `import` and `export`
- CommonJS uses `require` and `module.exports`
Node.js lets JavaScript run outside the browser, especially for servers, tooling, CLIs, and build pipelines.
- Node.js is a runtime, not the language
- CommonJS uses `require` and `module.exports`
- npm and package.json manage dependencies and scripts
Objects can be created in several ways, and property access depends on whether the key is static or dynamic.
- Object literals are the common default
- Dot access needs a valid identifier
- Bracket access handles dynamic keys