InterviewSolution
| 1. |
Java vs JavaScript |
|
Answer» The === is a comparison operator in JavaScript. It checks for the value as well type. Same value and type Let US SEE an EXAMPLE wherein we have assigned a numeric value to variable “val1” and checked it with a numeric value for EQUALITY (type and value): <!DOCTYPE html> <html> <body> <h2>JavaScript === operator</h2> <p id="test"></p> <script> var val1 = 20; document.getElementById("test").innerHTML = (val1 === 20); </script> </body> </html>The output displays that the variable has the same value and type. Therefore, TRUE is returned as output: Same Value and Different Type Let us see an example wherein we have assigned a numeric value to variable “val2” and checked it with a value of another type for equality (type and value): <!DOCTYPE html> <html> <body> <h2>JavaScript === operator</h2> <p id="test"></p> <script> var val2 = 5; document.getElementById("test").innerHTML = (val2 === "5"); </script> </body> </html>The output displays that the variable has same value but different type. Therefore, false is returned as output: |
|