Today #day24 of #100daysofcode, I have completed 2 lessons and a practice program in JS. @Sololearn
Math Operators
Arithmetic operators
- the arithmetic operators are
+
,-
,/
,*
,%
,++
,--
,,
,,
Note:
\
is escape character.- eval() function text string argument can perform arithmetic operations. Example:
var x = 10 + 5;
document.write(x);
document.write("<br>"+eval("5+9/6*4%79-862"))
Code: Output
Note:
- multiplying string type of number value with a number will give output.
- but multiplying string type of string value with a number will result error i.e
NaN
- in Python multiplying and number with a string type of string value multiply the string value in the house
- you can add a string type of number value to a number.
- you can add string type of string value to a number.
var x = 10 * 5;
document.write("10 * 5\ = "+x);
document.write("<br>"+"\"10\" * 5\ = "+"10"*5);
document.write("<br>"+"\"Hi\"*5\ = "+"Hi"*5);
document.write("<br>"+"\"10\"+5\ = "+"10"+5);
document.write("<br>"+"\"Hi\"+5\ = "+"Hi"+5);
Code: Output
increment and decrement operators
- the increment operator increases the value it's operate by one,
a=0,b=0
,a++
thena=1
.
Note:
a=b++ --> a=0,b=1
a=++b--> a=1,b=1
Assignment operators
=
,+=
,-=
,*=
,/=
,%=
Image
Conclusion
- Arithmetic operators.
- Increment and decrement operators.
- Assignment operators.