After learning about variables, you can now see how console.log()
becomes even more useful in JavaScript. This method is primarily used for finding errors in the code. It allows developers to check the values of variables at each point in the code and verify that they are working as intended.
Let’s see how console.log()
can help us keep track of variable values.
In the code above, we can confirm that the assignment statement works as expected by logging the variable's value before and after the update. As we continue learning, we will write more complex code and logging values at different points will help us make sure that our results are as expected.
When a project is finished, console.log()
statements are often removed or disabled, as they are mainly a tool for development.