Basics: Operators and expressions

Operators allow you to get two simple expressions and combine them to form a more complex expression.

But first.. what is an expression? An expression is a single unit of JavaScript code that the JavaScript engine can evaluate, and return a value.

An expression can be a literal, like a string or a number.

It can also be an identifier that points to a variable.

Like these:

age //where 'age' is the name of a variable
{} //an empty object

We also have other kinds of expressions.

Arithmetic expressions are expressions that take a variable and an operator (more on operators soon), and result in a number:

1 / 2
i -= 2
i * 2

String expressions are expressions that result in a string:

'A ' + 'string'

Logical expressions make use of logical operators and resolve to a boolean value:

a && b
a || b

More advanced expressions involve objects, functions, and arrays, and I’ll introduce them later.

Lessons in this unit:

0: Introduction
1: Literals, identifiers and variables
2: Comments
3: The difference between let, const and var
4: Types
5: ▶︎ Operators and expressions
6: Let's start with arithmetic operators
7: The assignment operator
8: Operators precedence
9: Strings
10: Numbers
11: Semicolons, white space and sensitivity
Are you intimidated by Git? Can’t figure out merge vs rebase? Are you afraid of screwing up something any time you have to do something in Git? Do you rely on ChatGPT or random people’s answer on StackOverflow to fix your problems? Your coworkers are tired of explaining Git to you all the time? Git is something we all need to use, but few of us really master it. I created this course to improve your Git (and GitHub) knowledge at a radical level. Launching May 21, 2024. Join the waiting list!