- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Write the main difference between '==' and '===' operators in javascript?
The difference between '==' and '===' is that former checks only value but the latter checks value and also data type(String, Boolean etc).The following example gives whether values assigned are equal or not irrespective of datatype.
a) "==" operator(checks equality)
Example
<html> <body> <p id="strict"></p> <script> var x = 5; var y = 5; var z = 6; document.getElementById("strict").innerHTML = (x == y) + "<br>" + (x == z); </script> </body> </html>
Output
true false
b) '===' operator (Checks strict equality)
"===" operator gives true if and only if both value and data type are equal.If not it returns false.In the following example every variable(x,y,z) has assigned value 5 but some of them were given string data type(variables y and z).When we strict equals x and y we get false because variable y is assigned string data type whereas variable x is not.
Example
<html> <body> <p id="strict"></p> <script> var x = 5; var y = "5"; var z = "5"; document.getElementById("strict").innerHTML = (x === y) + "<br>" + (x == z); </script> </body> </html>
Output
false true
- Related Articles
- what is the main difference between '=' and '==' operators in javascript?
- The difference between 'AND' and '&&' in MySQL?
- What is difference between '.' , '?' and '*' in Python regular expression?
- Difference between 'include' and 'extend' in Ruby
- What is the difference between 'throw new Error' and 'throw someObject' in javascript?
- Difference between 'struct' and 'typedef struct' in C++?
- What is the difference between 'isset()' and '!empty()' in PHP?
- What is the difference between 'log' and 'symlog' in matplotlib?
- Difference between 'struct' and 'typedef struct' in C++ program?
- What is the difference between the 'COPY' and 'ADD' commands in a Dockerfile?
- What is the relation between 'null' and '0' in JavaScript?
- Finding the sum of two numbers without using '+', '-', '/', '*' in JavaScript
- What is the difference between 'except Exception as e' and 'except Exception, e' in Python?
- How and why does 'z'['toUpperCase']() in JavaScript work?
- Update 'a' record with 'b' and 'b' with 'a' in a MySQL column (swap) with only 'a' and 'b' values?

Advertisements