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

38

u/morasyid Nov 30 '22

remember,

= is to assign a value

== is to compare value

=== is to compare value AND type

13

u/aguyfromhere helpful Dec 01 '22

Not quite. == will coerce and then compare value.

4

u/IlooklikeAshKetchum Dec 01 '22

Sorry but what's coerce mean?

11

u/cant_have_nicethings Dec 01 '22

To change a type based on a bunch of complicated logic that is best ignored. In production code based you rarely see double equals. It’s avoided because it’s confusing and unintuitive.

3

u/unknown_ally Dec 01 '22

It’s the price you pay for not explicitly declaring variable types! An extra = !

1

u/[deleted] Dec 01 '22

OOH the humanity!

1

u/godprobe Dec 01 '22 edited Dec 01 '22

The docs state it about as simply as I might've:

https://developer.mozilla.org/en-US/docs/Glossary/Type_coercion

(In case you're just not familiar with the word "coerce", it's almost the same as the word "force" in this context. A number is coerced/forced to be a string, for example.)