A JavaScript program is a sequence of statements. Each statement is an instruction for the computer to do something
if (/* expression slot */) {
// More statements here
}
A JavaScript program consists of a sequence of statements. Each statement
is an instruction to do something, like create a variable, run an
if/else
condition, or start a loop
Statements are the rigid structure that holds our program together, together
with expressions they build the basics of writting js
programs
Statements often have slots
for expressions
. We can put any expression
we like into those slots.
A statement
has an otherwise empty expresion slot that can be filled
with any kind of expression
/*
For the following expresion:
let hi = {{some expression}};
*/
let hi = 1;
let hi = "hello";
let hi = 5 * 10;
let hi = num > 100;
let hi = isHappy ? "🙂" : "🙁";
let hi = [1, 2, 3].pop();
Want to know whether a chunk of JS is an expression or a statement? Try to log it out!
If it runs, the code is an expression
. If you get an error, it's a statement
(or, possibly, invalid JS). With this we can also see what the expression
resolves to, as it will be printed out
console.log(/* Some chunk of JS here */);