What is the best way to learn the fundamentals of JS? I will talk about my process of building the foundations of JS.
Firstly, before starting JS I would recommend learning the basics of HTML and CSS as this will allow you to visualise everything you do in JS. Before learning JS I already have a C++ background so it wasn't very hard to learn the basics of this language as a lot of the basics transfer over from one language to another.
If you are starting from zero I would recommend watching full beginners guide on JS on YouTube as you can pause the video and play about with the things you are learning. When I learn something new for example when I first learned switch cases a while back, I created a custom function, which uses the switch cases within it to get a more of a 'feel' for the syntax. This will make you more comfortable using the new things you learn within other projects. After learning each little thing I would recommend on writing a mini program showing off what you learned as it will make you understand what you learned more and make you more comfortable using it down the line.
How I learned JS:
1- Variables: This was pretty easy to get a hang of it as all you have to do in JS is use the keyword
let
and it will auto assign the variable for you unlike other languages where you have to specify if the variable will be an int
or a string
.
2-Operators: Next thing you want to learn is how to manipulate data that you have. For example, adding/subtracting two numbers together. After learning operators I would write a simple program that takes in two numbers and an operator selector that would operate on the two numbers and print it out. This will make you more comfortable with using variables and operating on them.
3-Conditionals: Next up I would learn conditional like if
statement and switch cases
. Learning this will make you able to write more unique programs as you can tailor the output from what's been inputted by the user. You can use this to create that mini program I was talking about earlier as you can perform different operations depending on the input from the user.
4-Loops: Learning Loops is a necessity if you want to create games as you need something called a game loop. (A never-ending loop). They will also help you iterate through objects (not covered here). For loops are great for iterating through objects whereas, while loops are good at game loops or recursion. You can create a program that will loop and add 1 to a variable until it hits a certain number.
These are the very foundations of learning JS. You will need these if you are going to progress further on in learning different features. After mastering these I would recommend learning objects and arrays (a form of an object).