Console.log() is Your BestFriend!
DRC7
Posted on July 13, 2022
For Beginners
If you're just starting out in the world of programming, then you may have already been introduced with a console.log("Hello World!)
. If not, consider this your first one! At the moment, we may all think this console.log
is meaningless. But the fact of the matter is, it is a very helpful tool.
What is Console.log()
By definition, provided by GeeksforGeeks, The console.log() is a function in JavaScript which is used to print any kind of variables defined before in it or to just print any message that needs to be displayed to the user.
Syntax: console.log(A);
Parameters: It accepts a parameter which can be a string, an array, an object or any message.
Return Value: It returns the value of the parameter given, to the web console.
Let's go ahead and put this information to use.
Let's Log!
Example:
let firstName = "Curious"
let lastName = "George"
console.log(firstName)
console.log(lastName)
console.log(firstName + lastName)
Now, here in this very simple block of code you can see that we have set firstName to Curious and lastName to George. So, if we run our console.logs we will receive three logs. "Curious", "George", and " Curious George". As developers we should always console log after every line of code no matter how simple it may look. Why, you may ask? This insures us that the code is either working or what every developer dreads an error code.
If your code seems to be working fine then proceed with your programming and jump to the next line of code. If your code is receiving an error then run for the hills! Just joking.. we reassess our code! Fix that line of code before we continue.
This will help you tremendously in the long run. You will be able to catch any type of code error right then and there. Instead of creating a bunch of code and then running it, to find a whole bunch of errors that'll give you that migraine we all hate.
So please, use the console.log() you'll thank me later.
Posted on July 13, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.