When do you use console.log?


When do you use console.log?


Whenever you wish to log some output to the console. Say we want to print a list...

var birds = [ 'sparrow', 'robin', 'swallow', 'crow', 'magpie', 'chickadee']

for (var i = 0; i < birds.length; i++) {


We may wish to log the result of a computation done by a function...

var factorial = function (x) {
    p = x;
    while (--x > 0) {
        p *= x;
    return p;    

console.log(factorial(7));    // 5040


hi guys! i'm a newbie and doesn't know everything yet in javascript... can you tell me what's the difference between console.log and document.write, when to use console.log and when to usedocument.write??


We use console.log() when we want to log output to the debugging console. The rather outdated, document.write() is used to output HTML and raw text to the browser window. For the time being, set this aside and pour yourself into the introductory lessons of the JS track. Most focus is on the console, since we aren't working with HTML in the module.


Some examples you can find here: JavaScript Output


:slight_smile: thank you :slight_smile:


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.