Questions tagged [console.log]

a debugging tool for JavaScript. It is method of the console object which logs the given object in the Browser's JS console.

log method of the console object is a method mainly used for debugging purposes.

Syntax

console.log(obj1 [, obj2, ..., objN]);

Parameters

obj1...objN - A list of JavaScript objects to output. The string representations of each of these objects are appended together in the order listed and output.

Example

Here is a simple JavaScript example which illustrates the use of console.log:

var foo = {'id':7, 'name':'John Doe'};
console.log(foo);

Output (in the console) - {id:7, name:"John Doe"}.

Note - The result my vary depending upon the browser's implementation of console.

Browser Compatibility

This feature is fully-supported on the latest versions of all the major browsers.

  • Mozilla Firefox 4+
  • Microsoft Internet Explorer 8+ (only after opening the F12 developer tools)
  • Google Chrome 1+
  • Opera 10.50+
  • Apple Safari 3+
2040 questions
68
votes
2 answers

Chrome console shows me "Navigated to http://localhost...."

Chrome console shows me "Navigated to http://localhost...." in blue letters Image:
63
votes
5 answers

Why does console.log say undefined, and then the correct value?

console.log("hi") gives undefined hi console.log(1+1) gives undefined 2 Whether it's a string or integer calculation, I get undefined then the correct answer. Why do I get the undefined message? Is there a good way to avoid it?
Michael Durrant
  • 93,410
  • 97
  • 333
  • 497
59
votes
2 answers

Google Chrome console.log() inconsistency with objects and arrays

I was helping a colleague debug some code today and I noticed a strange behavior with console.log() in Google Chrome: It appears that if you: Create a nested array (e.g., [[345,"test"]]) Log the array to the console with console.log(). Modify one…
Elliot B.
  • 17,060
  • 10
  • 80
  • 101
58
votes
1 answer

JavaScript - adding style to the text of console log

Recently I logged into my FB account on Chrome Browser. When I opened the developer tools, I saw something like this: Now I know that it is possible to add anything to console using the javascript console.log function. But my question is -- how did…
Ruchir Gupta
  • 990
  • 3
  • 10
  • 20
56
votes
1 answer

Winston Logger - NodeJs Debug console logs not showing in VSCode

I'm using VSCode debugger and winston logger for NodeJS, but can't see output from application unless I specify external terminal like this: "version": "0.2.0", "configurations": [ { "type": "node", "request": "launch", …
Josip
  • 1,061
  • 1
  • 9
  • 10
53
votes
4 answers

Does console.log invokes toString method of an object?

As per this documentation, The string representations of each of these objects are appended together in the order listed and output. Also as per answer The + x coerces the object x into a string, which is just [object Object]: So, my…
gurvinder372
  • 66,980
  • 10
  • 72
  • 94
51
votes
3 answers

Remove index from console.table()

I am viewing an array of data in the console. console.table(myArray) always has the index as the first column. This is fine when viewing object data, when the index is the key, but not when the index is the array index (in my case it is distracting/…
mrj
  • 849
  • 2
  • 8
  • 18
48
votes
2 answers

What is Service Worker Console? & Where is it in Chrome Browser?

I am working on push notifications and came upon an unfamiliar term: service worker console. I have read and used the term console log or web console in browser, but I am not familier with the term service worker console, and I didn't find…
45
votes
6 answers

Change console.log message color

Is there a way to do something like: console.log("hello world", '#FF0000') in Chrome/Safari or Firefox ?
Blacksad
  • 14,906
  • 15
  • 70
  • 81
44
votes
8 answers

How can I Display a JavaScript ES6 Map Object to Console?

I'm using repl.it/languages/javascript. Do I have to convert it to an object before I print it out? I've tried const mapObject = new Map(); mapObject.set(1, 'hello'); console.log(JSON.stringify(mapObject)); …
newguy
  • 5,668
  • 12
  • 55
  • 95
43
votes
6 answers

How to console.log an object definition and a text in same string?

I have this JavaScript code: console.log(obj);// [query: "wordOfTheDay"] console.log(note + " : " + obj ); // obj does not show up I want to make "obj" display in the same string as "note" no matter the type it come in as. For…
Ciprian Gheorghite
  • 535
  • 1
  • 4
  • 6
40
votes
7 answers

console.log() from node_modules

How do I console.log() from dependencies in node_modules in my node project? I'm using the default create-react-app setup. When I include console.log() in my application code, logging works fine. However, when I try to include console.log() in the…
artooras
  • 6,315
  • 9
  • 45
  • 78
38
votes
6 answers

How to watch console.logs in ionic emulator?

I'm building an app using the Ionic framework, which I've done in the browser until now. Because I now want to use the cordovaOauth plugin I need to use the emulator. The problem is that I can't see any console.log() in the emulator as I do in the…
kramer65
  • 50,427
  • 120
  • 308
  • 488
37
votes
7 answers

How can remove console.log in the production build of a React application created using create-react-app?

How can remove console.log in the production build of a React application created using create-react-app CRA?
Ajay
  • 1,255
  • 1
  • 17
  • 30
37
votes
3 answers

What is the difference between window.console.log and console.log

Just went through an interview. The first question asked me was what is console.log(). I answered with so confidence. Again, The second question was, what is the difference between window.console.log() and console.log(). I was speechless. Tried…
Santosh
  • 3,477
  • 5
  • 37
  • 75