JavaScript statements include values, operators, expressions, keywords, and comments. For example, this instruction tells the browser to insert “Hello Dolly.” into an HTML element with id=”demo”:
Example
document.getElementById(“demo”).innerHTML = “Hello Dolly.”; |
Most JavaScript programs are composed of multiple statements executed sequentially in the order they are written.
JavaScript programs, as well as individual JavaScript statements, are frequently referred to as JavaScript code. |
Semicolons ;
Each executable JavaScript statement is terminated with a semicolon.
Example
let a, b, c; // Declare 3 variables |
When delineated by semicolons, it’s permissible to have multiple statements on a single line.
a = 5; b = 6; c = a + b; |
You may encounter instances on the web where semicolons are omitted. While it’s not obligatory to conclude statements with semicolons, it’s strongly advisable to do so. |