What is console.log?

前端 未结 22 2335
面向向阳花
面向向阳花 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:14

    Quoting MDN Docs here

    console — contains many methods that you can call to perform rudimentary debugging tasks, generally focused around logging various values to the browser's Web Console.

    By far the most commonly-used method is console.log, which is used to log the current value contained inside a specific variable.

    How to use in Javascript?

    let myString = 'Hello World';
    console.log(myString);
    

    Also remember console is a part of global window object in the web browser. Thus the following is also technically correct but isn't used in practical scenario.

    let myString = 'Hello World';
    window.console.log(myString);
    

提交回复
热议问题