4

Html tag with a unique id can be used as a variable named the id directly ?

code:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <input type="text" id="mytest">
</body>
    <script>
        console.log(mytest);
        console.log(mytest === document.getElementById('mytest'));
        console.log(Object.hasOwnProperty(window,'mytest'));

    </script>
</html>

outputs : enter image description here

How could this be ? Where is mytest?

passion
  • 1,250
  • 9
  • 15

0 Answers0