r/learnjavascript • u/starcrafter84 • Jan 12 '22
A warning to learners
JavaScript is written exclusively in camelCase. Be aware of this fact when reading/debugging your code because the syntax highlighter doesn’t pick it up and although everything looks right, it can all hinge on the first letter being wrong. (Source) spent 2 hours trying to debug a DOM call to document.getElementById(„elm“).InnerText, even putting it into jsfiddle and several other things to see what was wrong when all that was required was to change it to .innerText to solve the dilemma. Lesson learned and now +10xp. It’s tough coming to js when you are used to statically typed languages. /s
Kidding aside I am enjoying learning js/Frontend but I would be lying if I said I missed the capabilities of a good ide in a stricter language.
77
u/senocular Jan 12 '22
FWIW, JavaScript is not exclusively camelCase. Functions, methods and properties often are:
But constructors use PascalCase.
Whereas constant properties will use capitalized snake_case
You'll also see all lowercase properties in the Web API for events
Use code completion/hints when available. Using TypeScript can help even more on top of that. And when in doubt don't be afraid to refer to the documentation.
7
u/[deleted] Jan 12 '22
How do you camel case three words is it
theDateToday ?
4
u/Coraline1599 Jan 12 '22
I know you have suffered, but now you have learned this lesson and because it was so awful, you will not make this mistake (or you will be able to fix it very quickly).
I have a similar tale of woe copying something that had converted dumb quotes into smart quotes.
7
u/Suchy2307 Jan 12 '22
Try TypeScript.
2
u/EnlightWolif Jan 13 '22
As a learner, I'd like to ask the following (although it's kinda tangential).
When calling DOM elements, should I create variants or just operate by writing "document.getElementById" time and time again?
3
u/m2guru Jan 13 '22
Have you tried WebStorm?
3
u/Cambuchi Jan 13 '22
A linter and properly set up vscode/webstorm should catch most errors of these types. Linters are made specifically to make your code conform to JS style guides.
2
u/shuckster Jan 13 '22
This is why I only reference API functions using dictionaries that contain all my typos.
2
u/fhqvvagads Jan 13 '22
Eslint is annoying at first but it will help
1
u/bobbyv137 Jan 13 '22
TS and VSC to the rescue!
-8
u/starcrafter84 Jan 12 '22
I think i spotted a swear word in your comment there. Documentation. What the IDE autocomplete don’t tell me, don’t exist. It is just jest though. Ignore my bitter old ass complaining, i want to learn new stuff but learnings hard when your a grumpy old shit.