Conditions with if and else
Conditions choose which block runs based on a boolean expression. Keep conditions readable and use strict comparisons where possible.
Conditions choose which block runs based on a boolean expression. Keep conditions readable and use strict comparisons where possible.
Loops repeat work. A for loop suits a known number of iterations, while a while loop runs as long as its condition remains true.
JavaScript adds behavior to websites. It can respond to clicks, update page content, validate inputs, and communicate with servers.
The developer console helps inspect values and debug code. console.log() prints information, while console.error() highlights errors.
Use const when a variable binding should not be reassigned and let when reassignment is needed. Avoid var in modern beginner code.
Common types include string, number, boolean, undefined, null, object, and bigint. typeof can inspect most types, but typeof null is a historical quirk.
Arithmetic operators calculate values; comparison operators compare them. Prefer === and !== to avoid implicit type conversion surprises.
Strings hold text. Template literals use backticks and ${} expressions to combine values into readable messages.