Asked 7 years ago
11 Jan 2017
Views 1427
web-api

web-api posted

What is console.log() in JavaScript ?

what is use of console.log() in JavaScript ?



what are the other function and usage of it , like

console.assert()
console.clear()
console.count()
console.debug()
console.dir()
console.dirxml()
console.error()
console.group()
console.groupCollapsed()
console.groupEnd()
console.info()
console.markTimeline()
console.memory
console.profile()
console.profileEnd()
console.table()
console.time()
console.timeEnd()
console.timeStamp()
console.timeline()
console.timelineEnd()
console.trace()
console.warn()
Phpworker

Phpworker
answered Nov 30 '-1 00:00

console have all function to differ type of reporting at web browser console.
its good debugging technique . some developer use Alert box to get the debug result or some use document.write but i personally like console.log and other console function .lets discuss console.trace which is my favorite.
console.trace vs console.log

-> console.log is Just print on console where console.trace will print with info like who is calling it and show complete stack of calling .
lets try one recursion function to check how it behave .
console.log


function sub(d){ if(d==0) {return round;} else {d--;console.log(d);sub(d)}  }

simple function of subtract value and print its evolution per stage . i used console.log to see it output at every recursion.

you can see console.trace give us detailed output with debugger link , with stacked all call in recursion , i check with chrome browser console.
jessica

jessica
answered Nov 30 '-1 00:00

console.log is used to log to console. here console means browser console
console.log give me complete inner structure of variable , function or object
suppose
script have

console.log(console)

it will give complete inner structure . give all list of methods and all variable associated with console .
console.log(obj) means write obj to direct console of browser
console.log(cache) will give you output like this in chrome





summary is console.log is used in debugging process by JavaScript Developer

console.clear() used to clear browser console at any time

console.debug() give same output as console.log() do .


Post Answer