What is console.log?

前端 未结 22 2353
面向向阳花
面向向阳花 2020-11-22 00:41

What is the use of console.log?

Please explain how to use it in JavaScript, with a code example.

22条回答
  •  别那么骄傲
    2020-11-22 01:22

    Use console.log to add debugging information to your page.

    Many people use alert(hasNinjas) for this purpose but console.log(hasNinjas) is easier to work with. Using an alert pop-ups up a modal dialog box that blocks the user interface.

    Edit: I agree with Baptiste Pernet and Jan Hančič that it is a very good idea to check if window.console is defined first so that your code doesn't break if there is no console available.

提交回复
热议问题