This is my body
10 + 5
It will display a result ’15’;
Also, you can catch your DOM element.
Each statement ends with semi-colon (;).
Comments can be done with //single_line_code or /* code block */.
var and variable name. Keep in mind, variable name cannot start with number.
var myVariable; //or var myNextVariable = 100;
Assignment Operator:It assigns a variable with some value.
var age = 30;
Subtraction Operator: It displays difference between operands.
30 - 20 //outputs: 10
Multiplication Operator: It multiply two operands.
30 * 20 //outputs: 600
Division Operator: It divides top number by bottom number.
30 / 15 //outputs: 2
Addition Operator: It is used to concatenate two strings.
"Hello" + " World" //outputs: Hello World "Hello" + 5 //Hello5
Math Operator Short hand
Short-hand for adding is done by
var a = 10; var a += 20; alert(a); //output: 30
Similarly, substraction can be done using same technique.
var a = 300; var a -= 200; alert(a); //output: 100
var a = 10; var a *= 20; alert(a); //output: 200
var a = 10; var a /= 5; alert(a); //output: 2
Incrementing or decrementing a variable by 1 can be done by ++ or —
var a = 10; var b = 10; var a++; var b--; alert(a); //output: 11 alert(b); //output: 9
Logging in Console
You can write in the document by using document.write(). Also, you can write in the console using console.log()
console.log('I am logged');
Defining boolean variable:
var status = true; //OR Boolean(10 > 9) // returns true