Sample html, nothing special. But what's going on here?
<script>
console.log(myDrawing);
</script>
Above code seems to be running fine! How is that even possible that element with id is exposed to global scope with variable named by id? I don't understand what's going on here...
I have tested this in chrome, edge and safari - all seems to work the same.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1.0"
/>
<title>Document</title>
</head>
<body>
<svg
id="myDrawing"
class="animated v1"
width="200"
height="200"
viewBox="0 0 200 200"
style="border: 1px solid #000"
>
<circle
class="eye"
cx="50"
cy="50"
r="40"
stroke="green"
stroke-width="4"
fill="yellow"
/>
<circle
class="eye"
cx="150"
cy="50"
r="40"
stroke="green"
stroke-width="4"
fill="yellow"
/>
<rect
class="mouth"
x="50"
y="150"
width="100"
height="20"
fill="red"
/>
<rect
class="mouth smile"
x="30"
y="130"
width="20"
height="20"
fill="red"
/>
<rect
class="mouth smile"
x="150"
y="130"
width="20"
height="20"
fill="red"
/>
</svg>
<script>
console.log(myDrawing);
</script>
</body>
</html>