-1

I am trying to console.log in chrome. just basic stuff.this is my html file:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <h1>hello</h1>
    <button onClick="clickme()">click</button>

    <script type="text/javascript" src="index.js"></script> 
</body>
</html>

now my js file include

var name="abc";
console.log("hello " + name);
 clickme=()=>{
   document.body.style.backgroundColor="red";

   alert(name);
     console.log("hello " + name);

} 

The alerts work. The background image gets change on button click but the console.log is not working. It works using node js and when used in edge browser. Is there something missing.

Joaquin
  • 2,013
  • 3
  • 14
  • 26
amrit chhetri
  • 785
  • 8
  • 12

2 Answers2

1

Make sure you have Info checked in your Default-levels dropdown settings: enter image description here

console.log() always returns undefined (correct me if I am wrong), but prints the value passed to it in the console.

Saif
  • 2,530
  • 3
  • 27
  • 45
0

https://codesandbox.io/s/p9zjw8lxrm

Here I have an alert and console.log. You can see alert is running, but console.log does not get to run until you close the alert.

var name = "abc";
console.log("hello " + name);

document.getElementById("btn").onclick = function() {
  clickme();
};

const clickme = () => {
  document.body.style.backgroundColor = "red";

  alert(name);
  console.log("hello " + name);
};

When you first run the problem, you should see an alert, then after would be the console.log

When you load up the page,

First you get hello abc

Then Alert box, you click yes

Then hello abc

leogoesger
  • 3,476
  • 5
  • 33
  • 71