当前位置: 动力学知识库 > 问答 > 编程问答 >

What is console.log() in javascript?

问题描述:

This question already has an answer here:

  • What is console.log?

    20 answers

网友答案:

It's used for printing messages/values to the javascript console (in Chrome it's under View -> Developer -> JavaScript Console). See here for the docs.

网友答案:

You can use it to output some information in the browser's console. Usually it is done for debugging purposes.

网友答案:

It is useful for printing out debugging information in the browsers console while developing. In Chrome hit Ctrl + Shift + I to open the developer tools and switch to the Console to view output.

A developer may use this to verify that a line of JS is actually being reached, ie Console.log( "Reached Here" ); or to verify that a variable holds the value expected. Console.log( "Value of x is: " + x );

It is also very useful if you are writing JS for the server side using Node.js. This will allow you to log requests to the server and other useful information.

Console.log should probably be limited on the client side though, IE in real websites, especially if they were used for debugging as it may reveal site vulnerabilities. I have also seen Console.log cause issues in some versions of Internet Explorer.

分享给朋友:
您可能感兴趣的文章:
随机阅读: