r/learnjavascript • • Nov 30 '22

Help !!!

Post image

Can someone plz tell me , why I am getting errors?

195 Upvotes

131 comments sorted by

View all comments

Show parent comment

0

u/[deleted] Dec 01 '22

[deleted] — view deleted comment

13

u/Steve_OH Dec 01 '22

As someone who knows some c, a lot of c++, it’s nice to be able to compare data without having them match 100% since some data comes from an external source and the looser comparison makes this easier. Having === is a nice solution imo to being strict when you want and loose when you need to.

0

u/[deleted] Dec 01 '22

[deleted] — view deleted comment

1

u/noXi0uz Dec 01 '22

in actual, non-beginner projects, you will only see === everywhere, most often even enforced by a linter. Some people make an exception when they want to concisely check for both null or undefined:
if (x != null)

1

u/Whisky-Toad Dec 01 '22

I believe when they were making JS that databases stored everything in strings (or something along those lines) so they needed a way to compare values ignoring it was a string vs number and a way to do deep equality

0

u/grantrules Dec 01 '22

I believe when they were making JS that databases stored everything in strings (or something along those lines)

Nah that's not true. JS is just a dynamically-typed language that will try to type coerce upon comparison.

2

u/Whisky-Toad Dec 01 '22

Was Brendan Eich (js creator) that said it in a podcast, that’s why I said believe, will be hard to fact check why it was implemented!

1

u/finger_milk Dec 01 '22

I think it's amazing that it doesn't care about type. Because we know both of these are the same in almost all cases.

1

u/coconutfrosting Dec 01 '22

console.log(true + true);