-
Use
const
, thenlet
- When creating a variable, you should use
const
, unless you expect you variable to change, in which case, you should uselet
. Never usevar
, especially as a beginner. If you're not sure whether your variable will change, always useconst
. Keeping with this rule will generate errors in your code that help you understand the nuanced differences betweenconst
andvar
over time. Intellectual curiosity will eventually lead you down that rabbit hole of addressing "scope" with this point. For now, stick with this role.
- When creating a variable, you should use
-
Default to triple equality
- JavaScript has this funky behavior of implicit type conversion (or coercion) that forces your variable into a type, based on the context. This is what allows you to add a string and a number. But when testing for a condition, using triple equality (
===
) insures that JavaScript will interpret your code exactly how you wrote it.
- JavaScript has this funky behavior of implicit type conversion (or coercion) that forces your variable into a type, based on the context. This is what allows you to add a string and a number. But when testing for a condition, using triple equality (
-
Start with Model View Controller (MVC)
- The first design pattern I learned will of course be my easiest to understand; so I may be biased. But having explored a few design patterns since my first line of code, I find MVC to be the most beginner friendly. MVC organize your code according to your programs concerns:
- Model layer will hold your data model (your database)
- View is the visual / presentation layer
- Controller handles communication between the Model and View
- The first design pattern I learned will of course be my easiest to understand; so I may be biased. But having explored a few design patterns since my first line of code, I find MVC to be the most beginner friendly. MVC organize your code according to your programs concerns:
-
Try the module design pattern
- Once you have a good grasp of the MVC pattern (or if you just want to learn an additional pattern), check out the module design patter covered here. Using this patter will encourage you to break your code into small functional components that each do one thing. This is a good habit to develop early.
-
Learn functional programming before Object Oriented Programming
- I'm sure you've heard that JavaScript is both a functional and an object-oriented language. Of the two, functional programming is easier and has a shorter learning curve than OOP. While there are hundreds of blogs to argue both sides of that statement, you can start building with FP before understanding classes, instances, inheritance and more. OOP can also be challenging if you don't have a good understanding of what your objects will be, also explored here.
- Functional programming, on the other hand, is easy to get started with. It's about having modular code that focuses on what your functions do, instead of what your objects are. Again, developing great habits early.
-
Always use template literals
- Template literals are not only easier to read, but also easier to write, especially with multi-line strings. Switching to back ticks can be a bit awkward at first, but the small amount pain is completely worth never having to use a
+
sign to create a new line.
- Template literals are not only easier to read, but also easier to write, especially with multi-line strings. Switching to back ticks can be a bit awkward at first, but the small amount pain is completely worth never having to use a
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (9)
Thank you! This is very helpful to a beginner like me!
You're welcome! Let me know if there are any questions I can help you answer 😊
Some comments may only be visible to logged-in visitors. Sign in to view all comments.