What Is Console.Log

What is console.log?

It's not a jQuery feature but a feature for debugging purposes. You can for instance log something to the console when something happens. For instance:

$('#someButton').click(function() {
console.log('#someButton was clicked');
// do something
});

You'd then see #someButton was clicked in Firebug’s “Console” tab (or another tool’s console — e.g. Chrome’s Web Inspector) when you would click the button.

For some reasons, the console object could be unavailable. Then you could check if it is - this is useful as you don't have to remove your debugging code when you deploy to production:

if (window.console && window.console.log) {
// console is available
}

Why is console.log used? What does it do?

It logs things to a debug console (which is built into many browsers (e.g. Chrome Developer Tools) and available as an extension (e.g. Firebug for Firefox) in many others)

Is console.log() a javascript built-in method?

console.log() is a feature for debugging purposes. It allows a script to log data to the JavaScript console.

If you want to display the message from console.log() in your browser, you need to access the browser's console.

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

For at least IE, Firefox and Chrome consoles, .debug() is just an alias for .log() added for improved compatibility

https://developer.mozilla.org/en-US/docs/Web/API/console

https://developers.google.com/chrome-developer-tools/docs/console-api#consoledebugobject_object

https://msdn.microsoft.com/en-us/library/ie/hh772183(v=vs.85).aspx

What's the difference between console.dir and console.log?

In Firefox, these function behave quite differently: log only prints out a toString representation, whereas dir prints out a navigable tree.

In Chrome, log already prints out a tree -- most of the time. However, Chrome's log still stringifies certain classes of objects, even if they have properties. Perhaps the clearest example of a difference is a regular expression:

> console.log(/foo/);
/foo/

> console.dir(/foo/);
* /foo/
global: false
ignoreCase: false
lastIndex: 0
...

You can also see a clear difference with arrays (e.g., console.dir([1,2,3])) which are logged differently from normal objects:

> console.log([1,2,3])
[1, 2, 3]

> console.dir([1,2,3])
* Array[3]
0: 1
1: 2
2: 3
length: 3
* __proto__: Array[0]
concat: function concat() { [native code] }
constructor: function Array() { [native code] }
entries: function entries() { [native code] }
...

DOM objects also exhibit differing behavior, as noted on another answer.

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

In a normal browser context, there is no difference. console is a global variable, and all globals are properties of the window object.

console.log(console.log==window.console.log) // true

Node.js console.log vs console.info

According to the documentation that you linked to, console.error and console.warn outputs to stderr. The others output to stdout.

If you are doing piping or redirection from node.js the difference is important.

There is a lot of JavaScript written to run in both the browser and Node.js. Having node implement the full console allows for greater code cross-compatibility.

In most browsers, not only do these log in different colors, but you can also filter to see specific messages.

console.info("info");
console.error("error");
console.warn("warn");
console.log("log");

How to do logging in React Native

console.log works.

By default on iOS, it logs to the debug pane inside Xcode.

From the iOS simulator, press (+D) and press Remote JS Debugging. This will open a resource, http://localhost:8081/debugger-ui on localhost. From there, use the Chrome Developer tools JavaScript console to view console.log



Related Topics



Leave a reply



Submit