Languages / JavaScript Core
Language Basics
Statements, variables, operators, control flow, functions, and errors.
JavaScript syntax at a glance
JavaScript blurs the line between statements and expressions more than C-style languages do, and parsers apply automatic semicolon insertion when you omit terminators. This chapter maps strict mode, script versus module goals, and the syntactic habits that surprise newcomers from Java, Go, or Python.
Variables and declarations
Three declaration keywords—var, let, and const—interact with hoisting and the temporal dead zone in ways that differ from block-scoped languages like Java or Rust. const only freezes the binding, not deep object contents. This chapter is the reference for choosing among them in modern code.
Operators in JavaScript
Beyond familiar arithmetic and comparison, JavaScript adds nullish coalescing, optional chaining, and logical assignment operators that behave differently from || and && in other languages. Precedence tables from C do not fully apply; this page covers the operators that change control flow and defaulting logic.
Control flow in JavaScript
if and switch follow C-shaped syntax, but switch uses strict equality and falls through unless you break. Labeled break and continue apply to any statement, not only loops—a feature most statically typed languages omit. Ternary expressions fill the same niche as other languages’ inline conditionals.
Loops in JavaScript
for-of iterates values; for-in walks enumerable keys and is the wrong default for arrays. Classic for loops with var still show up in legacy code and create closure bugs in callbacks. break, continue, and labels behave like C, with for-await-of added for async iterables.
Functions in JavaScript
Functions are first-class values: declarations hoist differently from const bindings, arrow functions inherit lexical this, and the rest parameter replaces most uses of the arguments object. Default parameters run at call time and can reference earlier parameters—unlike overload sets in Java or C#.
Destructuring and spread
Destructuring unpacks arrays and objects into bindings; spread copies iterables and expands objects in literals. Together they replace much of the manual indexing common in Java or Go. Rest in patterns collects leftovers without the arguments object.
Error handling in JavaScript
JavaScript has no compile step in the browser: syntax fails at parse time, everything else surfaces at runtime through throw and the Error hierarchy. try/catch/finally, the cause option, custom Error subclasses, and AggregateError cover sync code and Promise rejection paths.