To understand this better, take a look at the set of statements given below.
var a = 2; var b = 2; var total; total = a + b; alert(total);
var a, b, total; a = 2; b = 2; total = a + b; alert(total);
- = the equal sign
- + addition
- – subtraction
- * multiplication
- / division
- var – to declare a variable
- function – to declare a function
- if – assigning a set of statements to be executed depending a specific condition
- return – to stop working in a function and return a variable
- while – to assign a set of statements to be repeated while a certain condition holds true.
- switch – to assign a set of statements to be executed depending on different situations.
//this is a comment var name = prompt("What is your name?"); //'prompt' is used to get user input alert("Hello " + name + "!"); //greet user using their response
Types of expressions include String expressions, Arithmetic expressions, Logical expressions, Object creation expressions, Function defining expressions and much more. We’ll be looking more at expressions more in a later article.
Take a look at this numeric expression.
var realPrice = price - (price * (discount/100)); And here is a string expression.
var sweet = "Pumpkin" + " Pasty";