Can someone clarify the use of console.log() in JS? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

Can someone clarify the use of console.log() in JS?

27th May 2018, 7:26 AM
Abbhinav Bharadwaj
4 Answers
+ 8
Console.log() prints the message in the console. It is used for testing purpose. Console.log("something") prints something in a console.
27th May 2018, 7:30 AM
Akash Pal
Akash Pal - avatar
+ 3
By the Console.log() you can also leave messages easly to the next developer:)
27th May 2018, 10:29 AM
Netanel Bezalel
Netanel Bezalel - avatar
+ 3
console.log() is used for testing purposes. It simply prints the info on the console window. Open any browser and go to the developer menu (In Firefox press F12) then go to the Console tab & try writing something. Example: console.log("SoloLearn"); // Output: SoloLearn var myVar=“Coding is fun”; console.log(myVar); // Output: Coding is fun
7th Jun 2018, 8:23 AM
Aaditya Kr Dhiman
Aaditya Kr Dhiman - avatar
+ 1
Here's some examples of using console.log(). These all output to the console, and not a web page: console.log('Hello world!'); // outputs Hello world! var txt = 'This text'; console.log(txt); // outputs This text console.log(txt + ' is ' + 'concatenated'); // outputs This text is concatenated console.log(2+3); // outputs 5 Using console.log() can be useful while developing, as it can show whether or not you reach a certain point in your code, and also what is being output. Hope this helps!
28th May 2018, 2:45 AM
Joe DeSoto
Joe DeSoto - avatar