{"id":18048,"date":"2023-03-15T12:40:00","date_gmt":"2023-03-15T07:10:00","guid":{"rendered":"https:\/\/www.guvi.in\/blog\/?p=18048"},"modified":"2025-10-24T15:31:13","modified_gmt":"2025-10-24T10:01:13","slug":"differences-between-and-operators-in-javascript","status":"publish","type":"post","link":"https:\/\/www.guvi.in\/blog\/differences-between-and-operators-in-javascript\/","title":{"rendered":"4 Key Differences Between == and === Operators in JavaScript"},"content":{"rendered":"\n<p>JavaScript, which is the most demanding and high-paying programming language comes with various benefits. Not only build web applications, but JavaScript also helps in developing game applications, web servers, etc. There are various elements in JavaScript that can be used during the implementation of projects. One of them is &#8211; <strong>Operators in JavaScript. <\/strong><\/p>\n\n\n\n<p>Operators in JavaScript play an important role in manipulating data. To perform operations in data, we use operators which modify it and can be used in programs. From adding two numbers to comparing two values, every single operation can be performed using operators in JavaScript. <\/p>\n\n\n\n<p>In this blog, we&#8217;ll be focusing majorly on <strong>comparison operators which include == and ===. <\/strong>This topic is the most confusing one as developers get confused as to which one to choose and on which condition. So, let&#8217;s discuss the<strong><em> differences between the == and === operators in JavaScript.<\/em><\/strong><\/p>\n\n\n\n\n\n<h2 class=\"wp-block-heading\">Differences Between == and === Operators in JavaScript<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>== Operator<\/strong><\/td><td><strong>=== Operator<\/strong><\/td><\/tr><tr><td>Compares two variables without caring about their datatype<\/td><td>Compares two variables along with their datatype<\/td><\/tr><tr><td>It returns true if variables are the same, without caring about its datatype<\/td><td>It returns true only if both the values and data types are the same<\/td><\/tr><tr><td>Also known as abstract\/loose equality<\/td><td>Also known as strict equality<\/td><\/tr><tr><td>It performs the type conversion when both the variables are of different type<\/td><td>It does not follow type conversion if both variables have a different datatype<\/td><\/tr><\/tbody><\/table><figcaption class=\"wp-element-caption\">Top differences between == and === operators in JavaScript<\/figcaption><\/figure>\n\n\n\n<p class=\"has-text-align-center\"><strong><em>If you want to master Javascript, consider exploring JavaScript through\u00a0<a href=\"https:\/\/www.guvi.in\/courses\/web-development\/advanced-javascript\/?utm_source=blog&amp;utm_medium=organic&amp;utm_campaign=differences-between-and-operators-in-javascript\" target=\"_blank\" rel=\"noreferrer noopener\">HCL GUVI&#8217;s JavaScript self-paced certification course<\/a>.<\/em><\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Operators in JavaScript<\/h2>\n\n\n\n<p>While using <a href=\"https:\/\/www.guvi.in\/hub\/javascript\/\" target=\"_blank\" rel=\"noreferrer noopener\">JavaScript<\/a>, you can work on operators that help you perform operations such as calculations, assigning values to operands, comparing values, working on logical functions, etc. <strong><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Guide\/Expressions_and_Operators\" target=\"_blank\" rel=\"noreferrer noopener\">Operators in JavaScript<\/a> <\/strong>let you perform such operations in a few seconds while coding. Some of the operators in JavaScript are &#8211;<\/p>\n\n\n\n<ul>\n<li>Assignment Operators<\/li>\n\n\n\n<li>Arithmetic Operators<\/li>\n\n\n\n<li>Comparison Operators<\/li>\n\n\n\n<li>Logical Operators<\/li>\n\n\n\n<li>Bitwise Operators<\/li>\n<\/ul>\n\n\n\n<p>We&#8217;ll be focusing much on comparison operators as this blog is majorly focused on<strong> == and === operators<\/strong> which fall under the category of comparison operators.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Comparison Operators<\/h3>\n\n\n\n<p>Comparison operators let you <strong>compare their operands and return a logical value based on the given statement.<\/strong> They are used in logical statements to determine the equality between variables or values. The output for comparison comes in Boolean value i.e., true or false. They are used in decision-making and loops. Also, the operands used in operations can be of data types like numerical, string, logical, or object values. <\/p>\n\n\n\n<p>Some of the symbols that describe the operations are &#8211;<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>&lt;<\/td><td><em>less than<\/em><\/td><\/tr><tr><td>&gt;<\/td><td><em>greater than<\/em><\/td><\/tr><tr><td>&lt;=<\/td><td><em>less than or equal to<\/em><\/td><\/tr><tr><td>&gt;=<\/td><td><em>greater than or equal to<\/em><\/td><\/tr><tr><td>==<\/td><td><em>equal to<\/em><\/td><\/tr><tr><td>!=<\/td><td><em>not equal to<\/em><\/td><\/tr><\/tbody><\/table><figcaption class=\"wp-element-caption\">Symbols in Comparison Operators<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">== and === Operators in JavaScript<\/h2>\n\n\n\n<p>We&#8217;ll be discussing the differences between == and === operators in JavaScript, why should you use and their use cases. Let&#8217;s dive deep into them.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">== Operator in JavaScript<\/h3>\n\n\n\n<p>== Operator in JavaScript is the <strong>abstract equality comparison operator also known as loose equality<\/strong>. It checks whether both the variables being compared have the same value or not. If both have the same value, irrespective of the data type of the variable (operand), it returns true, else if both have different values, the output comes as false. <\/p>\n\n\n\n<p>Also, here <em>boolean, numbers, and strings<\/em> are compared by value, not by reference, and if they have the same equivalent value then are considered true. == operator converts the value of the variable to the same type before comparing. This is why it is also called<strong> type coercion. <\/strong><\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Example of == Operator<\/strong><\/h4>\n\n\n\n<ol>\n<li><code>console.log(42 == 42);<\/code><\/li>\n\n\n\n<li><code>console.log(21 == '21');<\/code><\/li>\n\n\n\n<li><code>console.log(21 == '32');<\/code><\/li>\n\n\n\n<li><code>console.log(true== 0);<\/code><\/li>\n<\/ol>\n\n\n\n<p><strong>The output of the above-mentioned code:<\/strong><\/p>\n\n\n\n<ol>\n<li>true<\/li>\n\n\n\n<li>true<\/li>\n\n\n\n<li>false<\/li>\n\n\n\n<li>false<\/li>\n<\/ol>\n\n\n\n<p><strong>Explanations of the output &#8211;<\/strong><\/p>\n\n\n\n<p><em>Since, the == operator only looks after the values whether they&#8217;re the same or not, not the data type of both variables. <\/em><\/p>\n\n\n\n<p><em>In example 1, we have the same values being compared, hence the output is true. <br>In example 2, we have the same values with different data types, hence the output is true caring only about the variable, not the data type.<br>In example 3, we have different values being compared, hence the output is false.  <br>In example 4. we have the boolean value true as 0 which is technically not right (true=1, false=0), hence the output is false.<\/em><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">=== Operator in JavaScript<\/h3>\n\n\n\n<p>=== Operator in JavaScript is the<strong> strict equality comparison operator <\/strong>which only returns true if both the value of the variables (operands) and the data type of the variables are the same, else false. It checks for the value and the data type of the variables and after comparing both sides, if it satisfies both the given conditions, returns true, if not, it returns false. <\/p>\n\n\n\n<p>It strictly compares two values, where it does not perform any type of coercion. === operator<strong> performs typecasting,<\/strong> it strictly compares two values. <\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Example of === Operators<\/strong><\/h4>\n\n\n\n<ol>\n<li>console.log (18===&#8217;18&#8217;);<\/li>\n\n\n\n<li>console.log (isha === &#8216;isha&#8217;);<\/li>\n\n\n\n<li>console.log (false === false);<\/li>\n\n\n\n<li>console.log (1.9 === 19);<\/li>\n<\/ol>\n\n\n\n<p><strong>The output of the above-mentioned code:<\/strong><\/p>\n\n\n\n<ol>\n<li>false<\/li>\n\n\n\n<li>true<\/li>\n\n\n\n<li>true<\/li>\n\n\n\n<li>false<\/li>\n<\/ol>\n\n\n\n<p><strong>Explanations of the output &#8211;<\/strong><\/p>\n\n\n\n<p>Since the === operator looks after both the data and the data type, it checks the data and then the data type of the variables and then produces the output when both conditions are satisfied.<\/p>\n\n\n\n<p><em>In example 1, only the data is the same, not the data type, hence the output is false<br>In example 2, we have both the values and data type the same, hence the output is true.<br>In example 3, we have both the values and data type the same, hence the output is true.<br>In example 4. we have both the data and the data type different, hence the output is false.<\/em><\/p>\n\n\n\n<p><strong><em>Do check out <a href=\"https:\/\/www.guvi.in\/courses\/web-development\/advanced-javascript\/?utm_source=blog&amp;utm_medium=organic&amp;utm_campaign=differences-between-and-operators-in-javascript\" data-type=\"link\" data-id=\"https:\/\/www.guvi.in\/courses\/web-development\/advanced-javascript\/?utm_source=blog&amp;utm_medium=organic&amp;utm_campaign=differences-between-and-operators-in-javascript\" target=\"_blank\" rel=\"noreferrer noopener\">HCL GUVI&#8217;s self-paced Javascript certification course<\/a> which covers all the concepts required for you to have a good grip on it.<\/em><\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>Now that you know the major differences between the <strong>== and === operators in JavaScript,<\/strong> you can start implementing these. Where the == operator is used to compare two variables, the === operator compares two variables with the data type. Apart from these operators, we have many other operators as well which can be used in JavaScript coding. Have a deep understanding of the <strong>operators in JavaScript <\/strong>and use them precisely while building applications. This can help you develop web applications effectively. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>JavaScript, which is the most demanding and high-paying programming language comes with various benefits. Not only build web applications, but JavaScript also helps in developing game applications, web servers, etc. There are various elements in JavaScript that can be used during the implementation of projects. One of them is &#8211; Operators in JavaScript. Operators in [&hellip;]<\/p>\n","protected":false},"author":17,"featured_media":18062,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[429],"tags":[],"views":"9800","authorinfo":{"name":"Isha Sharma","url":"https:\/\/www.guvi.in\/blog\/author\/isha\/"},"thumbnailURL":"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2023\/03\/diff-300x93.jpg","jetpack_featured_media_url":"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2023\/03\/diff.jpg","_links":{"self":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/18048"}],"collection":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/users\/17"}],"replies":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/comments?post=18048"}],"version-history":[{"count":30,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/18048\/revisions"}],"predecessor-version":[{"id":91165,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/18048\/revisions\/91165"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/media\/18062"}],"wp:attachment":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/media?parent=18048"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/categories?post=18048"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/tags?post=18048"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}