I will post some questions in JavaScript from today onwards share your own solutions without running these code on your console.
null === undefined
null == undefined
2+"4"
2-"3"
""+2
+"2"
I will post some questions in JavaScript from today onwards share your own solutions without running these code on your console.
null === undefined
null == undefined
2+"4"
2-"3"
""+2
+"2"
For further actions, you may consider blocking this person and/or reporting abuse
Oldest comments (40)
Got 3. and 5. wrong, haha.
I supposed that the first operand would decide which implementation of + would be used, but I guess the rule is: string wins :D
Both convert the number to string and do a string concatination, even in one the number is the first operand and in the other the string is the first operand.
Ah, yes.
I was talking about 3 and 5 :D
Oh i thought it was 5 and 6.
yeah 3 and 5 are Strings😁
Looking forward for the next questions 😀
false
true
"24"
-1
"2"
true
Not sure about some of these.
Edit: Got five right!
false
true
"24"
-1
"2"
error ?
Tested it, only have one wrong
good try
Syntax error on 3 and 4, beware of trailing periods!
Edit: OP removed the trailing periods!
6 uses + as a short form for type conversion
Without looking:
I love these! I even have a codepen that's kind of like this
Oh, yeah, I know my weird Javascript math 🎉
1 and 2 I know because of work since null and undefined can be a pain when testing.
3 is string concatination with 2 being made a string to make it magically work.
4 is making the string a number to make the math operator magically work.
5 is similar to 3 in that it's concatinating an (empty) string with a number that magically becomes a string.
6 is fun because
+
is the shorthand for type converting to an int.In the past I collected some strange behaviour of JavaScript:
github.com/bullgit/WAT/blob/master...
:-)
One of my favorite web-slinger questions (for fun, not for job interviews) is: can you name all 8 of the falsy things?
Here's the first falsy thing, to get you started, which is pretty much a gimme:
I'm out. What are the last 2?
Shoutout! I didn't get
NaN
-NaN and -0
Here they all are. I realize that two of them will bring out the angry mob with their torches and pitchforks. But my disclaimer is that I did not write the language.
First the easy 6 falsy things:
Plus the final two falsy things, the second of which being an HTML-ism (part of the HTML specification):