Javascript Operators

Javascript Operators explained:

Javascript Operators: Operators are used in all programming languages to do calculations, assign, compare and retrieve results from various functions and events. Similarly, JS uses operators to the same. Below are a few Javascript operators:

Addition: Javascript uses the sign + for addition of numeric values.

Example: 2+2 the result is 4 in JS.

Concatenation: Javascript uses plus + sign for concatenating text values.

Example: “Johne” + “Ashbey” would return Johne Ashbey in JS.

Subtract: We use hyphen – sign for subtraction or minus in Javascript.

Example: 4-2 would result in 2

Multiply: Javascript applies asterisk(*) sign for multiplication.

Example: 4*2 should result 8 in JS.

Divide: JS has / forward slash or division symbol for dividing numbers.

Example: 8/2 will result in 4.

Assignment: Assigning a value to a variable is done using equal sign(=). But keep in mind that it assigns a value to a variable, it does not equate unlike == sign.

Example: var x = 10;

Identity Operator: Javascript uses (==) double equal sign to check if one value is equal to another or not. The JS returns either true or false after the test is applied:

Example:

Var myScore = 10;

Var myScore == 20;  

The above would reflect in JS as false. 

————————————————————————————

Leave a Reply