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
1441
votes
19 answers

How can I get the full object in Node.js's console.log(), rather than '[Object]'?

I have this object: const myObject = { "a":"a", "b":{ "c":"c", "d":{ "e":"e", "f":{ "g":"g", "h":{ "i":"i" } } } } }; But when I try to show it…
user1372449
900
votes
9 answers

Node.js: printing to console without a trailing newline?

Is there a method for printing to the console without a trailing newline? The console object documentation doesn't say anything regarding that: console.log() Prints to stdout with newline. This function can take multiple arguments in a…
Evan Carroll
  • 78,363
  • 46
  • 261
  • 468
461
votes
36 answers

Can't access object property, even though it shows up in a console log

Below, you can see the output from these two logs. The first clearly shows the full object with the property I'm trying to access, but on the very next line of code, I can't access it with config.col_id_3 (see the "undefined" in the screenshot?).…
Brian Litzinger
  • 5,409
  • 3
  • 23
  • 21
432
votes
26 answers

What is console.log?

What is the use of console.log? Please explain how to use it in JavaScript, with a code example.
Mihir
  • 8,696
  • 18
  • 56
  • 87
418
votes
22 answers

JavaScript console.log causes error: "Synchronous XMLHttpRequest on the main thread is deprecated..."

I have been adding logs to the console to check the status of different variables without using the Firefox debugger. However, in many places in which I add a console.log in my main.js file, I receive the following error instead of my lovely little…
Nathan Basanese
  • 8,475
  • 10
  • 37
  • 66
308
votes
22 answers

Console.log statements output nothing at all in Jest

console.log statements output nothing at all in Jest. This was working for me yesterday, and all of sudden, it's not working today. I have made zero changes to my config and haven't installed any updates. I'm not using the --forceExit option. Still…
Hina Dawood
  • 3,201
  • 2
  • 10
  • 8
254
votes
28 answers

Configure Node.js to log to a file instead of the console

Can I configure console.log so that the logs are written on a file instead of being printed in the console?
Randomblue
  • 112,777
  • 145
  • 353
  • 547
214
votes
7 answers

Difference between console.log() and console.debug()?

Google has not been helpful for me, since searching for "console.debug" just brings up a bunch of pages that have the words "console" and "debug" on them. I'm wondering what the difference is between console.log() and console.debug(). Is there some…
CaptSaltyJack
  • 15,283
  • 17
  • 70
  • 99
174
votes
7 answers

Is Chrome’s JavaScript console lazy about evaluating objects?

I’ll start with the code: var s = ["hi"]; console.log(s); s[0] = "bye"; console.log(s); Simple, right? In response to this, the Firefox console says: [ "hi" ] [ "bye" ] Wonderful, but Chrome’s JavaScript console (7.0.517.41 beta) says: [ "bye" ] […
Eric Mickelsen
  • 10,309
  • 2
  • 30
  • 41
163
votes
12 answers

How can I make console.log show the current state of an object?

In Safari with no add-ons (and actually most other browsers), console.log will show the object at the last state of execution, not at the state when console.log was called. I have to clone the object just to output it via console.log to get the…
user429620
140
votes
5 answers

Dumping whole array: console.log and console.dir output "... NUM more items]"

I am trying to log a long array so I can copy it quickly in my terminal. However, if I try and log the array it looks like: ['item', 'item', >>more items<<< ... 399 more items ] How can I log the entire array so I can copy it really quickly?
Anthony
  • 13,434
  • 14
  • 60
  • 80
112
votes
11 answers

How can I add a variable to console.log?

I'm making a simple game in JavaScript but in the story I need it to say the players name. so what I have so far is: var name = prompt("what is your name?"); console.log("story" name "story); how do I do the second line? or there is another way I…
Bradley McInerney
  • 1,341
  • 4
  • 15
  • 14
111
votes
10 answers

Printing to the console in Google Apps Script?

Back in 2012, I had some Google Apps Script code for a poker game: function addplayerstoArray(numplayers) { var playerArray = []; for (i=0; i
jim_shook
  • 1,245
  • 2
  • 9
  • 9
85
votes
5 answers

Access last logged value in Chrome console

When I evaluate an expression directly in the Chrome Console like 1 + 1 then I can reference to the evaluated value using $_ However, I can't access the value with $_, when the value is a result of a console.log, coming from inside of my…
Robin Drexler
  • 4,307
  • 3
  • 25
  • 28
69
votes
8 answers

Restoring console.log()

For some reason, the prototype framework (or another JavaScript code) that is shipped with Magento is replacing standard console functions, so I can't debug anything. Writing down in JavaScript console console I get the following output: >…
s3v3n
  • 8,203
  • 5
  • 42
  • 56
1
2 3
99 100