testing equality

showing the difference between == and === operators

Javascript

1 == 1 // this is true
1 == '1' // this is also true
1 == "1" // this is also true
1 === 1 // this is also true
1 === "1" // this it NOT true

Demo

if(1 == 1) {
  console.log('1 == 1 is true');
}

if(1 == '1') {
  console.log('1 == \'1\' is true');
} else {
  console.log('1 == \'1\' is NOT true');
}

if(1 == "1") {
  console.log('1 == "1" is true');
} else {
  console.log('1 == "1" is NOT true');
}

if(1 === 1) {
  console.log('1 === 1 is true');
} else {
  console.log('1 === 1 is NOT true');
}

if(1 === "1") {
  console.log('1 === "1" is true');
} else {
  console.log('1 === "1" is NOT true');
}


Welcome

This is my test area for webdev. I keep a collection of code snippits here, mostly for my reference. Also if i find a good site, i usually add it here.

❤👩‍💻🕹