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
17
votes
4 answers

How to omit file/line number with console.log

In the console of Chrome you can write pretty nice stuff these days. Checkout this link. I've also made a screenshot: As you can see in the screenshot too, the file name / line number (VM298:4) is written at the right. Is it possible the remove…
Jeanluca Scaljeri
  • 26,343
  • 56
  • 205
  • 333
17
votes
4 answers

How to log unicode characters to the console in JavaScript?

I have a Hungarian statement that I would like to log to the console like this: console.log('Probléma a működésben.'); But it prints the following: > Probléma a működésben. The non ASCII characters are messed up, but I don't think the reason…
totymedli
  • 29,531
  • 22
  • 131
  • 165
17
votes
1 answer

%j specifier in console.log excludes some properties

I was recently trying to load the bson (binary JSON) module in node.js. The API docs were unclear, so I thought inspecting the objects would help me. The results of the inspection were baffling. Finally I found out it was because I was using %j…
picomancer
  • 1,786
  • 13
  • 15
17
votes
3 answers

How is console.log() implemented?

Where can I learn about the implementations of console.log? To be clear, I know HOW to use console.log(), but I want to see the underlying implementations of console.log for some of the major browsers. Does console.log just echo input back into a…
charmander123
  • 357
  • 3
  • 11
16
votes
5 answers

How can I stop Jest wrapping `console.log` in test output?

I'm making a Jest test with request describe("GET /user ", () => { test("It should respond with a array of users", done => { return request(url, (err, res, body) => { if (err) { console.log(err) }…
16
votes
1 answer

Using `console.log` inside of a Worker in Chrome prints the same message twice

Pretty much what the title says. What is weirder is that this only happens when you run the program in a new tab, if you merely refresh the page, there will be only one message for each console.log. Here is main.js: const worker = new…
doubleOrt
  • 2,407
  • 1
  • 14
  • 34
16
votes
1 answer

How can I make console.group output to debug or info instead of log?

I try to keep console.log clean so I use console.debug and console.info when possible but how can I make it so that console.group logs to info or debug. It keeps putting an empty group in log. I don't see any option to change it to output…
Brennan Cheung
  • 4,271
  • 4
  • 30
  • 29
16
votes
1 answer

Is it a bug in firefox developer edition?

Take a look at the below code: var c = 50; { console.log(y); let y = 50; } This code is expected to throw a ReferenceError and it does. But in the console, the message attached with the exception just blown my mind. It…
16
votes
3 answers

How to output Buffer content completely with console.log

In nodejs console.log(new Buffer(12)) show < Buffer 00 22 33 11 55 ...> We know the ... ignore the following bytes. Now I want to output the whole buffer with 12 bytes, what should I do?
zangw
  • 43,869
  • 19
  • 177
  • 214
16
votes
3 answers

IE11 truncates string in console

I have a string of maybe 20 or 30 lines i'd like to output to the console all in one console.log call. This works great in Chrome, but IE11 truncates about half of the string in the console. Any way to prevent this? The string is something…
16
votes
6 answers

Node.js double console.log output

I'm learning Node.js and I'd like to understand the "why" when code spits out duplicated console.log outputs but only a single response.write outputs. Heres my simple code example: var http = require('http'); http.createServer(function(request,…
JDillon522
  • 19,046
  • 15
  • 47
  • 81
15
votes
2 answers

Google Chrome's console.log() prints DOM nodes inconsistently

Not a duplicate of Google Chrome console.log() inconsistency with objects and arrays, since this question is not about objects and arrays. Here is a simple HTML page:
15
votes
2 answers

Override console.log|error with winston no longer working

For a while we were using a simple lib to override the default console.log| error with winston, but it no longer works. This is our little module: const path = require('path') const fs = require('fs-extra') const { createLogger, format, transports }…
user1037355
15
votes
1 answer

How to open browser's JavaScript console programmatically?

How to open the browser's JavaScript console with JavaScript code? if (ShowConsole() == false) alert('I cannot open your JavaScript console, please " + "use your browser\'s menu to open manually.') else console.log('now you can see some…
exebook
  • 32,014
  • 33
  • 141
  • 226
14
votes
1 answer

Why does function.toString() output "[native code]", whereas logging to the console directly displays the function’s source code?

I decided to create a userscript for YouTube live chat. Here is the code: const toString = Function.prototype.toString unsafeWindow.setTimeout = function (fn, t, ...args) { unsafeWindow.console.log(fn, fn.toString(), toString.call(fn)) …
Wynell
  • 633
  • 1
  • 8
  • 15