Coding

JavaScript Expressions – JavaScript Tutorial

Task

How to Declare JavaScript Expressions

Description

Expression is combination of the values, variables, and operators which computes to a value.
The computation is called the evaluation.
For example 5 * 10 evaluates to 50:

Example

<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = 5 * 10;
</script>

Expressions can also contain variable values:

Example

<p id="demo"></p>
<script>
var x;
x = 5;
document.getElementById("demo").innerHTML = x * 10;
</script>

The values can be of various types, such as numbers and strings.
For example, “John” + ” ” + “Doe”, evaluates to “John Doe”:

Example

<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = "John" + " "  + "Doe";
</script>
Try It Yourself - Online Compliler >>