0
Why x == y, but x !== y in this script? JavaScript, DOM
<!DOCTYPE html> <html> <head> </head> <body> <p id="demo">text</p> <script> var x = document.getElementById("demo"); var y = "[object HTMLParagraphElement]"; if (x == y) { document.write("x == y"); } if (x === y) { document.write("x === y"); } </script> </body> </html> The output is: text x == y
4 Réponses
+ 4
It's a node element... (HTMLParagraphElement, as returned in string format ^^)
+ 4
x and y are not of same type...
you should compare:
x.toString() == y
+ 1
Thank you!!!
0
Thank you visph. What data type is variable "x"?