JavaScript Expressions and Statements
Expressions
In simple terms an expression is a fragment of code that produce a value. It’s doesn't matter how big or small is it. Also we have two different types of expressions, expressions with side effects and those that in some sense evaluate and therefore resolve to a value. for example:
let x = 7 // produce variable x -> with side effects
3+4 //produce 7 as a result -> resolve to a value
5 //produce 5 -> resolve to a value
Also JavaScript has the following expression categories:
- Arithmetic: evaluates to a number, much of the time use arithmetic operators like addition, subtraction, division and multiplication.
- String: evaluates to a character string, for example, “Fred” or “234”. Generally uses string operator like addition.
- Logical: evaluates to true or false. uses logical operators (&& and ||).
- Primary expressions: Basic keywords and general expressions in JavaScript. for example this keyword and Grouping operator ().
- Left-hand-side expressions: Left values are the destination of an assignment. for example new operator to create an instance of a class and super keyword to call functions on an object’s parent.
Statements
A program is a list of statements and every statement is separated by a semicolon. The simplest statement look like this:
1;
Well, It isn’t too much, but when you combine statements with expressions you can create a program of any type of size.
If you want to know more about it, check out this, Eloquent JavaScript and MDN Web Docs for Statements and Expressions.