JavaScript Expressions

Expressions

JavaScript Expressions

🙋 Need help? Ask an expert now!

Expressions are a sequences of operators, literals and variables that are evaluated to some value. Expressions have a type (integer, boolean, string) as well as a value. We've touched on this before when discussing operators and how boolean expressions can be evaluated using arithmetic/logical operators. An expression can be a statement as simple as 5 > 2 which evaluates to true.

The code above show three different arithmetic expressions. The first one is evaluated like this: (150 - 20) / 2 + 5 = 130 / 2 + 5 = 65 + 5 = 70. The other two are mathematical equations that calculate the area and perimeter of a circle given the radius. Expressions are used in almost any program to calculate numbers or boolean values when needed.

Edit Me on GitHub!

Application Question

What does the expression "70 / 2 * 2 * (5 - 3) - 10 / 2" evaluate to?