Console Object: The Console object provides access to the browser’s debugging console, which can be seen using F12 or ctrl+shift+j. Console object contains many methods, log() and dir() are most used among.
The console.log() method prints out a toString representation of the object in the console to the user.
console.log(object) or console.log("string", object)
The console.dir() method output the list of object properties of a specified object in the console to the user.
In simple words, the console.log() returns the object in its string representation and console.dir() recognizes the object just as an object and outputs its properties. Both log() and dir() returns the string just as a string.
In the above code,
log() prints the toString representation of the object while
dir() recognizes the object and prints its properties only.
The above program is runned in chrome, so log() prints the tree along with the string info, but if runned in firefox log() only prints out toString representation info, while dir() behaves the same anywhere.
As you can see in the code console.dir(“geek2 (dir) = “, geek2); only prints the string part but not the object properties because dir() take only one parameter and considers the string as its only parameter passed into the methods, whereas log() takes any number of parameters.
- Difference Between Blu-Ray and DVD
- Difference between Blu-ray and DVD
- Difference between IBM DB2 and MS SQL
- Difference between JSP and ASP
- Difference between TCP and RTP
- Difference between BFS and DFS
- Difference between RPC and RMI
- Difference Between Gi-Fi and Li-Fi
- What is the difference between GUI and CUI?
- Difference between GSM and LTE
- Difference between USB 2.0 and USB 3.0
- Difference between 1G and 2G
- Difference between PIP and HLP
- Difference between Tor and VPN
- Difference between ELT and ETL
- Difference between T-SQL and PL-SQL
- Difference between HLP and PCP
- Difference between PCI and PCI-X
- Difference between DVD-R and DVD-RW
- Difference between WCF and Web API
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.