Table of Contents
The Assignment Operator (=) assigns a value to a variable:
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Operators</h2>
<p>From w3schools.com, Experiment by Teeratus_R</p>
<h4>JavaScript Assignment</h4>
<p id="demo"></p>
<script>
let x = 10;
document.getElementById("demo").innerHTML = "x = " + x;
</script>
</body>
</html>

Result View Example
The Addition Operator (+) adds numbers:
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Operators</h2>
<p>From w3schools.com, Experiment by Teeratus_R</p>
<h4>JavaScript Addition</h4>
<p id="demo"></p>
<script>
let x = 5;
let y = 2;
let z = x + y;
document.getElementById("demo").innerHTML = "x + y = " + z;
</script>
</body>
</html>

Result View Example
The Multiplication Operator (*) multiplies numbers:
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Operators</h2>
<p>From w3schools.com, Experiment by Teeratus_R</p>
<h4>JavaScript Multiplication</h4>
<p id="demo"></p>
<script>
let x = 5;
let y = 2;
let z = x * y;
document.getElementById("demo").innerHTML = "x * y = " + z;
</script>
</body>
</html>

Result View Example
There are different types of JavaScript operators:
+, -, *, /, %, ++, --=, +=, -=, *=, /=, %=, **=+, +===, ===, !=, !==, >, <, >=, <=, ?&&, ||, !Arithmetic Operators are used to perform arithmetic on numbers:
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Operators</h2>
<p>From w3schools.com, Experiment by Teeratus_R</p>
<h4>Arithmetic Operators</h4>
<p id="demo1"></p>
<p id="demo2"></p>
<p id="demo3"></p>
<p id="demo4"></p>
<script>
let a = 10;
let b = 3;
document.getElementById("demo1").innerHTML = "a + b = " + (a + b);
document.getElementById("demo2").innerHTML = "a - b = " + (a - b);
document.getElementById("demo3").innerHTML = "a * b = " + (a * b);
document.getElementById("demo4").innerHTML = "a / b = " + (a / b);
</script>
</body>
</html>

Result View Example
The + operator can also be used to add (concatenate) strings:
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Operators</h2>
<p>From w3schools.com, Experiment by Teeratus_R</p>
<h4>String Addition (Concatenation)</h4>
<p id="demo"></p>
<script>
let text1 = "John";
let text2 = "Doe";
let text3 = text1 + " " + text2;
document.getElementById("demo").innerHTML = text3;
</script>
</body>
</html>

Result View Example
Adding two numbers will return the sum as a number.
Adding a number and a string will return the sum as a concatenated string:
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Operators</h2>
<p>From w3schools.com, Experiment by Teeratus_R</p>
<h4>Adding Strings and Numbers</h4>
<p id="demo1"></p>
<p id="demo2"></p>
<p id="demo3"></p>
<script>
let x = 5 + 5;
let y = "5" + 5;
let z = "Hello" + 5;
document.getElementById("demo1").innerHTML = "5 + 5 = " + x + " (number)";
document.getElementById("demo2").innerHTML = '"5" + 5 = ' + y + " (string)";
document.getElementById("demo3").innerHTML = '"Hello" + 5 = ' + z + " (string)";
</script>
</body>
</html>

Result View Example
Assignment operators assign values to JavaScript variables.
The Addition Assignment Operator (+=) adds a value to a variable:
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Operators</h2>
<p>From w3schools.com, Experiment by Teeratus_R</p>
<h4>Assignment Operators</h4>
<p id="demo1"></p>
<p id="demo2"></p>
<p id="demo3"></p>
<script>
let x = 10;
let y = 10;
let z = 10;
x += 5;
y -= 3;
z *= 2;
document.getElementById("demo1").innerHTML = "x += 5 => " + x;
document.getElementById("demo2").innerHTML = "y -= 3 => " + y;
document.getElementById("demo3").innerHTML = "z *= 2 => " + z;
</script>
</body>
</html>

Result View Example
Comparison operators are used to compare two values and always return true or false:
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Operators</h2>
<p>From w3schools.com, Experiment by Teeratus_R</p>
<h4>Comparison Operators</h4>
<p id="demo1"></p>
<p id="demo2"></p>
<p id="demo3"></p>
<script>
let x = 5;
document.getElementById("demo1").innerHTML = "5 == '5' is " + (5 == "5");
document.getElementById("demo2").innerHTML = "5 === '5' is " + (5 === "5");
document.getElementById("demo3").innerHTML = "5 > 8 is " + (5 > 8);
</script>
</body>
</html>

Result View Example
Document in project
You can Download PDF file.