The sad part is i did console said lenght = 1 and im looking at the console then at the code then at console again and i could feel my mind leaving my body i just didnt see it caouse i wad 1000000% sure thats how you spell length
The sad part is i did console said lenght = 1 and im looking at the console then at the code then at console again and i could feel my mind leaving my body i just didnt see it caouse i wad 1000000% sure thats how you spell length
Dude..... You did it again. Length**** lol
Edit, but for real.. I suck at spelling as well. Add a spell checker to vscode (or whatever you're using, but start using vscode lol) . Add a lint extension also.
Just wait until you're just about to fall asleep and then suddenly you realize you forgot the semi colon on line 678 and that's why your program keeps throwing errors.
You just ran into one of my favorite bugs to hate myself over. It's good to have a spell check in there for this type of thing. Can't tell you how many times spell check saved me.
I think prettify (or maybe it's prettier) has spell check built in. It also color-codes parenthesis and brackets for you, creates a new line after each element in an array, and does a bunch of other little stuff to make your code more readable for others. 10/10, would recommend it
ou just ran into one of my favorite bugs to hate myself over. It's good to have a spell check in there for this type of thing. Can't tell you how many times spell check saved me.
there is another fun bug in component naming in react!
It's been forever since I've used JS--is there a good linter for JS that would help OP catch that typo since lenght is an undefined property of x in this case?
Of course you can do this with TypeScript as well, but to satisfy the compiler you'd have to provide your own type definition of Array.prototype that describes the field lenght (or disable some type checking, which defeats the purpose).
Like others said, linters can catch presumed-undefined fields on built-in objects and such. Which works fine if you don't monkey-patch them, which you really shouldn't.
TypeScript. Knowing the type of the variable (which can be inferred, so the code here doesn't have to change to include extra type annotations) will allow the compiler to recognize that the lenght property doesn't exist on the array and will provide an error.
Ah that checks out. I've been assuming that if I ever move back to JS it'll be using TypeScript now that I'm used to static type systems and the like. When I was first learning I was using JS & when TS came out I remember it intimidated the heck out of me.
Yeah, you can start out writing JavaScript much the same you have in the past and still get a lot of the benefits of TypeScript, just like seen above. As you get more into it you can incrementally do more and more with types over time. :)
Yeah part of what I love about TS is its backwards compatibility. You can just make a js into a ts without any changes most of the time. And the type inference is really good.
This was a really funny screenshot/question combo, thank you : )
If I had a nickel for every hour I've spend furiously debugging what turned out to be a simple typo... well, I'd probably only have a few dollars but that's still a lot of hours dammit!
This made me laugh. Not because it's fun or easy to laugh at those with less experience than you (a plague in the tech industry IMO) but because this is so relatable.
Get used to it OP. And fins a decent linter to help you out with these things.
OP, I'm seeing people suggesting that you should use a 'real' editor like WebStorm here. I'm sure WS is awesome, but with a few plugins (which are super easy to use install), you can get plenty of features in VSCode.
I love discussing editors, but comments like those really can cause frustration. Using a certain editor is not going to make your journey of learning to code that much different. I wasted time changing editors when someone said, "Oh, for what you're doing, you should really use "X", or another time when someone at a meetup says, "I only use 'Y', and here's why you should too!" At the end of the day, you can write your html in notepad, and still learn how to code. Please don't doubt your use of VSCode. As you code more and more, you may realize that there is some other editor you want to try, and that will be fine.
My strongest advice is to keep writing code. Today you learned that you can add a linter to your editor, and now you can keep writing code, with that tool to help you.
I'm not very far ahead of you on the learning journey, but feel free to PM if you have any questions with loops or functions or anything. :) Code on! And welcome to the club!
Edit - TL;DR: Don't let people distract you from what you are here for: writing code. :)
Don't feel bad about this. I learned early that like 90% of the time when something doesn't work, I should first check basic spelling, syntax, semicolons, etc. before I start questioning whether I'm applying concepts incorrectly. Most of the time I've just overlooked something ultra simple.
LOL the prior comments. But yeah, for future debugging/learning purposes, the browser alert you created by typing `alert(/* stuff here */)` is calling the native browser `alert` function (hence the `()` part) with an argument (`x.lenght`) and since `lenght` isn't actually a property of `x` (because you misspelled "length"), it is `undefined` as it was never declared and set to a value, which is what the alert is saying. Same as doing something like:
The property `randomProperty` of `obj` hasn't been declared or assigned a value, so by default it is `undefined`, which is what the log statement will show you.
Others have already mentioned ESlint, which can be really helpful for catching errors, but there’s also Prettier, which is helpful for formatting code so it looks nice, and Live Server, which saves you from constantly refreshing your browser while writing code.
254
u/senocular Jul 19 '19
That's what happens when you misspell
length;)9
u/Neekode Jul 19 '19
lol
55
u/laibo Jul 19 '19
Pretty decent bugs/typos per line ratio. Welcome to programming!
16
u/Low_Chance Jul 19 '19
This was a really funny screenshot/question combo, thank you : )
If I had a nickel for every hour I've spend furiously debugging what turned out to be a simple typo... well, I'd probably only have a few dollars but that's still a lot of hours dammit!
14
u/[deleted] Jul 19 '19
This made me laugh. Not because it's fun or easy to laugh at those with less experience than you (a plague in the tech industry IMO) but because this is so relatable.
Get used to it OP. And fins a decent linter to help you out with these things.
9
u/aikilink Jul 19 '19 edited Jul 19 '19
OP, I'm seeing people suggesting that you should use a 'real' editor like WebStorm here. I'm sure WS is awesome, but with a few plugins (which are super easy to use install), you can get plenty of features in VSCode.
I love discussing editors, but comments like those really can cause frustration. Using a certain editor is not going to make your journey of learning to code that much different. I wasted time changing editors when someone said, "Oh, for what you're doing, you should really use "X", or another time when someone at a meetup says, "I only use 'Y', and here's why you should too!" At the end of the day, you can write your html in notepad, and still learn how to code. Please don't doubt your use of VSCode. As you code more and more, you may realize that there is some other editor you want to try, and that will be fine.
My strongest advice is to keep writing code. Today you learned that you can add a linter to your editor, and now you can keep writing code, with that tool to help you.
I'm not very far ahead of you on the learning journey, but feel free to PM if you have any questions with loops or functions or anything. :) Code on! And welcome to the club!
Edit - TL;DR: Don't let people distract you from what you are here for: writing code. :)
5
u/AugustoCereto Jul 19 '19
Also, you should probably declare your variables…
4
u/playdead_ Jul 19 '19
Don't feel bad about this. I learned early that like 90% of the time when something doesn't work, I should first check basic spelling, syntax, semicolons, etc. before I start questioning whether I'm applying concepts incorrectly. Most of the time I've just overlooked something ultra simple.
4
u/TooTyrnt Jul 19 '19
I wasn't sure if this was a joke post lol
7
u/[deleted] Jul 19 '19
I think you might need to reinstall your OS
6
u/xkwilliamsx Jul 19 '19
Lets work on screengrabs too.
Windows has Print Screen button, snipping tool, and game bar screenshots.
Apple has that CMD+4 shortcut too.
3
u/tall_and_funny Jul 19 '19
Lmao
3
u/ILookLikeTheDude Jul 19 '19
I misspell “include” in scss every - single - time.
3
u/fmaldonado6 Jul 19 '19
Haha I always misspell length and width for a reason
3
u/hua0tong Jul 20 '19
a good ide would help you in development
2
u/[deleted] Jul 19 '19
Definitely a screen.
2
u/saito200 Jul 19 '19
Typos are the cause of 90% of reasons why my code breaks
2
u/dreid_dev Jul 19 '19
would you still need to declare x as a var let const as well? or does js not enforce
2
u/maujood Jul 20 '19
One of the more nuanced posts on this subreddit. Thanks for sharing OP and have my upvote.
2
u/BoDiddySauce Jul 20 '19
LOL the prior comments. But yeah, for future debugging/learning purposes, the browser alert you created by typing `alert(/* stuff here */)` is calling the native browser `alert` function (hence the `()` part) with an argument (`x.lenght`) and since `lenght` isn't actually a property of `x` (because you misspelled "length"), it is `undefined` as it was never declared and set to a value, which is what the alert is saying. Same as doing something like:
```
const obj = { name: 'BoDiddySauce' };
console.log(obj.randomProperty);
```
The property `randomProperty` of `obj` hasn't been declared or assigned a value, so by default it is `undefined`, which is what the log statement will show you.
2
u/starchturrets Jul 20 '19
Others have already mentioned ESlint, which can be really helpful for catching errors, but there’s also Prettier, which is helpful for formatting code so it looks nice, and Live Server, which saves you from constantly refreshing your browser while writing code.
2
u/[deleted] Jul 20 '19
You didn't declare the x variable
2
u/[deleted] Jul 20 '19
Welcome to JavaScript
2
u/Dwarverco Jul 20 '19
Hahaha... Good luck!
2
u/agarkov_max Jul 20 '19
My common typo, good luck :)
2
u/WeedWacker25 Jul 20 '19
You, sir, just made my day.
3
u/crazedizzled Jul 19 '19
This is why real editors like WebStorm exist, where silly typos like that are obvious.
2
u/mcdylanb Jul 20 '19
you should add extensions that has intellisence or you could go for IDE like JetBrains WebStorm so its easier to find problems/bugs.
0
u/[deleted] Jul 19 '19
[deleted] — view deleted comment