Essential JavaScript


A JavaScript expression is anything that resolves to a value. We all know 1 + 2 = 3. The expression 1 + 2 resolves to 3. Similarly, 6 - 2 resolves to 4.

There are other types of expressions and values than numbers, but numbers make for easy examples.

When you run code in the practice editor, you will see the result of the last expression it evaluated. Basically, whatever your code does last (usually the final line in the editor) is what you will see as the result.

Multiple Expressions

Try running these three lines of code in the editor. Copy-paste them all:

1 + 2
3 + 5 - 1
55 / 11

Notice how the result is 5 because 55 / 11 is the last expression in the code. The previous expressions don't matter.

Be sure to put the expression you want to check at the very end.

No Expressions

Try deleting all code from the editor. Then submit it and see what happens.

The result should be undefined. This is the empty value in JavaScript. If we don't run any code, we don't get any result.

Some code simply doesn't return a value. In that case we will also get undefined as a result.

Learning Goals

Code Editor