Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,854 questions

51,775 answers

573 users

How to use equal comparison operators (=, ==, ===) in JavaScript

1 Answer

0 votes
var x = 13;
var y = 13;
if (x == y)  // true
    document.write("1. x == y" + "<br />"); 

x = 13;
y = 5;
if (x == y) // false
    document.write("2. x == y" + "<br />"); 

x = 13;
y = 5;
if (x = y) // true 
{
    document.write("3. x = y" + "<br />"); 
    document.write("3. x = " + x + "<br />"); 
    document.write("3. y = " + y + "<br />"); 
}

x = 13;
y = 0;
if (x = y) // false // x = 0 y = 0
    document.write("4. x = y" + "<br />"); 

x = 13;
y = 13;
if (x === y) // true
    document.write("5. x === y" + "<br />"); 
    
x = 13;
y = "13";
if (x === y) // false
    document.write("6. x === y" + "<br />"); 

if (x == y) // true
    document.write("7. x == y" + "<br />"); 
    

  
/*
run:

1. x == y
3. x = y
3. x = 5
3. y = 5
5. x === y
7. x == y

*/

 



answered Apr 16, 2017 by avibootz
edited Apr 17, 2017 by avibootz
...