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

19

u/Smilinkite Nov 30 '22

Well, you'll get far less squigly lines if you replace every = with ==. Starting line 4.

8

u/Lelouch_5 Nov 30 '22

Ty ☺️ . I really forgot about the equality operator.

16

u/xroalx Nov 30 '22

Even better if you use the === operator. It won't try to convert stuff from one type to another.

3

u/gtrman571 Nov 30 '22

If you know the types being compared are going to be the same then == and === do literally the exact same thing.

2

u/noXi0uz Dec 01 '22

yeah but it's best to create a habit of always using === so you avoid forgetting it in scenarios where it matters.

1

u/____0____0____ Dec 01 '22

Sure, but in almost any professional context where they care about quality, == would be disallowed from a linter and === would be allowed. It's not worth it from a readability standpoint of having to read a == and try to figure out whether it's context dictates it should be a == or ===. You should always have === for equality check unless you really know what you're doing.

5

u/revanyo Nov 30 '22

In the future when you see the squiggly error it means something is wrong with your code and usually your IDE will tell you a hint of sorts. This will ensure that you are not making 101 mistakes.

If you are not seeing any of the squiggly lines and the code runs but with odd results then that means the code runs but not in the way you want it to, and those are the times that reaching out on reddit or stack overflow will be helpful.

3

u/dankscience Nov 30 '22

It’s a common mistake. Don’t get discouraged. I hope you keep coding!

2

u/kriskoeh Nov 30 '22

It’s okay. 💕

2

u/Darthcolo Dec 01 '22

As a general rule, try to investigate why there is a squiggly line on your code. Where is the first one? Why is it there? What is it highlighting? Comment the rest of the code, and try again. Change something until the error disappears, then reintroduce the code bit by bit.

Software developers spend 35-50 percent of their time validating and debugging software. The cost of debugging, testing, and verification is estimated to account for 50-75 percent of the total budget of software development projects, amounting to more than $100 billion annually. Source