+ 5
Can someone clarify the use of console.log() in JS?
4 Antworten
+ 8
Console.log() prints the message in the console. It is used for testing purpose.
Console.log("something") prints something in a console.
+ 3
By the Console.log() you can also leave messages easly to the next developer:)
+ 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
+ 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!