Common math operations
1. Addition (+)
2. Substraction (-)
3. Multiplication (*)
4. Division (/)
5. Remainder (%) - This functions like the division but just gives the remainder as an answer.
6. Exponentiation (**)
7. Concatenation (+) - This combine two strings.
================
let message1 = "Hello ";
let message2 = "World";
function combineThem(){
return message1 + message2;
}
================
HTML
document.write(combineThem())
Result:
Hello World
Note: For other math operations, the String is automatically converted to Numbers.
8. Unary minus (-) - it converts the sign of the value from positive to negative or vice versa.
9. Unary plus (+) - it functions like in math when it comes to numbers but it is commonly used in converting different types to a Number.
+"5" = 5
So, the String "5" is automatically converted to Number 5 when you add the unary plus.
10. increment (++) => x++ is equivalent to x = x + 1
11. decrement (--) => x-- is equivalent to x= x -1
The only issue when using increment or decrement is when it is used either in postfix or prefix.
Example:
===============
let x = 5;
function incrementingX(){
return ++x;
}
===============
HTML
document.write(incrementingX())
Result:
6
Note: In ++x, the increment is used as prefix. x = x + 1 was performed first before returning the x. But if it was x++, meaning the increment was used as postfix. It will return first the x before performing the x = x + 1. So, if we change the ++x to x++ in the above program, the result would be 5.
There are other operators like bitwise operators and there is this operator precedence. Operator precedence is only applied if you are not using a parenthesis to specify which operation should go first.
YOU ARE READING
Javascript Programming
RandomI am just documenting things what i learned online in here. I do express things in my own words. And I create my own program samples which serves as my practice. I do this so that when someday I would need some notes to review, I can just visit in h...
