DEV Community

Discussion on: Beginner's Mistakes: Variables, Functions & Objects. . . Oh my!

Collapse
 
cstroliadavis profile image
Chris

Hi Tisha,

That's a pretty good start to understanding some of the complexities if JavaScript.

There are a couple things I'm not certain of your meaning. When I look at the array syntax you showed, it shows a name outside the list. That's not a format I've ever seen for arrays.

As for functions, you've shown one way of doing them, and as an experienced JavaScript developer, it's most definitely not my favorite trend, because it adds confusion to how and when functions can be used and may force functions to be ordered in a confusing and disorderly way, depending on how code is done.

Functions can be written this way

function multiply(num1, num2) {
return num1 * num2;
}

When you use the form where you assign an anonymous function to a constant, the function does not get named and can be harder to find in call stacks. Additionally, they can't be called until after they are assigned, which means if you have any code that is inline that is using that function, it must not be written until after the function declaration. This can really start cluttering up code.

JavaScript can seem a bit daunting at first. It's actually probably too easy to learn the fundamentals of JS. If I can offer a couple pieces of advice that will truly help beginners get the most out of JavaScript it's this. Focusing on writing, clean, organized, easy to read and understand code is top priority in most JavaScript based apps. One practice that can help most people do this with very little effort is to get into the habit of test first development (red, green, refactor). Write a unit test that tests a functional requirement. Make sure it fails (red). Make it pass with the most direct amount of coding needed (green). Clean up the code that made it work and make sure all tests continue to pass (refactor), then repeat for the next requirement. This practice is not only easier in JavaScript than it is in any other language, it is also more important in JavaScript than any other language. That's because JavaScript is extremely flexible and will let you write horrible code just as easily as good code and it will still work, but it will cost you dearly, later. TFD helps enforce good habits that JavaScript does not enforce itself.

Good luck, I wish you the best. JavaScript is truly a powerful, flexible language and mastery of it can be extremely useful.

Collapse
 
tallmanlaw profile image
Tisha Tallman

Chris,
Thank you for taking the time to read the blog and provide input! Very much appreciated. This is a very supportive community. I look forward to the journey.