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
37
votes
7 answers

Node.js console.log() in txt file

I have another question (last question). At the moment i am working on a Node.js project and in this I have many console.log() functions. This has worked okay so far but I also want everything that's written to the console to also be written in a…
Limatuz
  • 666
  • 2
  • 6
  • 12
37
votes
3 answers

How to create hyperlinks linked to javascript functions in Chrome's console.log?

I'm trying to write entries to the console that would contain links to trigger javascript functions upon clicking on them: console.log("javascript:alert('Hello World');"); console.log("
chamberlainpi
  • 4,854
  • 8
  • 32
  • 63
35
votes
3 answers

How to print stack trace with reference to typescript source in Nest.js

I am developing a Nest.js server and would like to be able to print useful stack trace in console (e.g. console.log). By default, it returns a reference to the line number in the compiled sources (.js). This is not useful for debugging as it's…
Alex Predescu
  • 792
  • 2
  • 7
  • 24
35
votes
3 answers

Access function location programmatically

Is it possible in code to access ["[[FunctionLocation]]"] property that google chrome developer tools show when using console log on a function ?
Sushruth
  • 1,074
  • 1
  • 9
  • 14
35
votes
7 answers

Removing console.log from React Native app

Should you remove the console.log() calls before deploying a React Native app to the stores? Are there some performance or other issues that exist if the console.log() calls are kept in the code? Is there a way to remove the logs with some task…
RRikesh
  • 14,112
  • 5
  • 49
  • 70
32
votes
8 answers

console.log browser in android emulator

How to see console.log messages of a website using android emulator?
coure2011
  • 40,286
  • 83
  • 216
  • 349
32
votes
2 answers

console.log() called on object other than console

I remember that always when I wanted to pass console.log as a callback parameter to some function, it didn't work unless I used the bind() method to bind console to it. For example: const callWithTest = callback =>…
Michał Perłakowski
  • 88,409
  • 26
  • 156
  • 177
31
votes
5 answers

Assign console.log value to a variable

How can I assign a JavaScript object to a variable which was printed using console.log? I am in Chrome console. With Ruby I would use test = _ to access the most recent item printed.
Dru
  • 9,632
  • 13
  • 49
  • 68
30
votes
2 answers

Webpack code splitting: ChunkLoadError - Loading chunk X failed, but the chunk exists

I've integrated Sentry with my website a few days ago and I noticed that sometimes users receive this error in their console: ChunkLoadError: Loading chunk failed. (error: /-.js) So I investigated…
5imone
  • 301
  • 1
  • 3
  • 7
28
votes
8 answers

Which browsers support console.log()?

Do all browsers support this? I would like to output an error using console.log() but was wondering if this supported by all browsers? console.log("Error etc");
KingKongFrog
  • 13,946
  • 21
  • 75
  • 124
27
votes
4 answers

React Native - Does console.log() hurt performance when going to production?

I have a lot of console.log() in my app. Most of them are in catch blocks, so I can clearly see what went wrong when developing. Some are there to log the current time so I can check function execution times. When deploying to production, those…
Yaron Levi
  • 12,535
  • 16
  • 69
  • 118
26
votes
8 answers

Console log in Javascript Office Addin

I have a question about "console.log" in Javascript Web Office Addins. Currently I am working on Javascript Word Addin and can't troubleshoot it, because I don't understand where the "console.log" output is sent. On Microsoft site there are a lot of…
Alexey Zelenkin
  • 701
  • 1
  • 6
  • 13
26
votes
10 answers

Javascript: Why sometimes alert() does not work but console.log() does?

From time to time, I face a very intriguing bug. My javascript code does not display an alert(msg) during execution, but if I use a console.log(msg) it does show up in the console. What could prevent alert() from displaying? Thanks a lot
siebmanb
  • 777
  • 1
  • 7
  • 15
24
votes
9 answers

Why is console.log() considered better than alert()?

I've always been told that when debugging an application, JavaScript's console.log() method is preferred over simply using an alert() method. Why is this? Is there a good example someone can point me to where console.log() is obviously the better…
Daniel Szabo
  • 7,181
  • 6
  • 48
  • 65
23
votes
4 answers

How to display console.log output in Visual Studio Code for html?

When I used brackets, there was a plugin to display console.log output in a panel below the source code panel, so I don't need switch to chrome and press F12 to view console.log output. But how to do that in Visual Studio Code? I use Visual Studio…
lionyu
  • 593
  • 3
  • 5
  • 14