what is the main difference between '=' and '==' operators in javascript?

JavascriptObject Oriented ProgrammingProgramming

The use of  "=" operator is that it assigns value from right to left, whereas "==" shows whether the given values are equal or not.In the following example variables x and y were assigned values using "=" operator and their magnitudes were checked using "==" operator.

Example

 Live Demo

<html>
<body>
<p id="equal"></p>
<script>
   var x = 5;
   var y = "6";
   document.write(x);
   document.getElementById("equal").innerHTML =
   (x == y);
</script>
</body>
</html>

Output

false
5
raja
Published on 21-May-2019 16:11:07
Advertisements