Home>

About the cases where () is attached or not in Javascript

When you have onclick attribute in html and in event property on script side
When I wrote oclick, I would like to know why ();

Applicable source code
<! DOCTYPE html>
<html>
  <head>
    <title>test</title>
  </head>
  <body>
    <p id = "ab">test</p>
    <script type = "text/javascript">
    function a () {
      console.log ("Hellow");
    }
    let p = document.getElementById ("ab");
    p.onclick = a;
    </script>
  </body>
</html>
<! DOCTYPE html>
<html>
  <head>
    <title>test</title>
  </head>
  <body>
    <p onclick = "a ();">test</p>
    <script type = "text/javascript">
    function a () {
      console.log ("Hellow");
    }
    </script>
  </body>
</html>

`` `Enter the language name here
javascript

If i add ();in the event properties, it will fire without permission.

Supplemental information (FW/tool version etc.)

chrome latest version

Trends