2
 console.log([2] == 2) //returns true
 console.log([2,3] == 2) //returns false
 console.log([2] === 2) //returns false
 console.log([2,3] === 2) //returns false

Can someone tell me what is happening behind the scenes in the above lines of code,how JavaScript Engine is performing these tasks

BeastLesnar
  • 71
  • 1
  • 3
  • 7
  • 2
    This should answer your question: https://stackoverflow.com/a/359509/6918960 – Icehorn Mar 28 '19 at 07:16
  • Keeping it simple: ```==``` means equal value, ```===``` means equal value and equal type. That will hopefully help you to understand the difference between the two. – Spangle Mar 28 '19 at 07:17
  • `==` - equal value, `===` - equal value and equal type. – Jack Bashford Mar 28 '19 at 07:19
  • 1
    Another useful resource: https://dorey.github.io/JavaScript-Equality-Table/ – VLAZ Mar 28 '19 at 07:33
  • @VLAZ Thanks for the useful resource,just one thing how type coercion is happening if L.H.S is an array and R.H.S is number or string of same value. – BeastLesnar Mar 28 '19 at 07:44
  • 1
    @BeastLesnar doesn't matter which side has which argument, with an array and a number, they would both be converted to the same basic type. An array will be converted to a number in this case. This is loosely, the result of `Number(array)`, so an empty array is `0`, an array with a single element is the value of that element, an array with multiple elements is `NaN`. The conversion is basically `Number(array.toString())` and `toString` in turn is `array.join()` with the default parameter for joining being `","`. In other words the `array` operand is transformed as if `Number(array.join(","))` – VLAZ Mar 28 '19 at 07:56
  • @VLAZ Thank you so much,it cleared my confusions – BeastLesnar Mar 28 '19 at 08:59

0 Answers0