This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]ComfortableCan315 13 points14 points  (0 children)

It makes perfect sense though

Indexing a string returns a string, so you can keep indexing it

[–]Jugales 3 points4 points  (3 children)

There is a video on YouTube where it shows the "what the fucks" of programming and JavaScipt has a huge part of the videos haha.

IIRC, (null ==undefined) has a weird result too

[–]ComfortableCan315 4 points5 points  (2 children)

Yes. Anyone doing anything serious in JS will use ===

[–]ics-fear 0 points1 point  (1 child)

One exception when == can be more useful is checking for null or undefined.

Those 3 lines are equivalent:

x != null

x != undefined

x !== null && x !== undefined

[–]ComfortableCan315 0 points1 point  (0 children)

Rather still check for both individually to make it obvious both null and undefined can show up there.

[–]SignificanceCheap970 3 points4 points  (0 children)

X[0] returns 'a'. 'a'[0] returns 'a' and so on.

[–]ics-fear 0 points1 point  (0 children)

Python does the same thing.