I'm following a JS course on Udemy, the teacher shows that snippet of code while explaining document:
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id="start">Start</div>
<ul>
<li>Element 1</li>
<li>Element 2</li>
</ul>
<button onclick="one()">Click!</button>
<button onclick="two()">Replace!</button>
<script>
function one() {
**x** = document.createElement("p");
x.innerHTML = 'Start Four';
document.getElementById('start').appendChild(x);
}
function two() {
y = document.createElement('p');
y.innerHTML = 'Start Five';
document.getElementById('start').replaceChild(y, **x**);
}
</script>
</html>
From what i have understood the variable x in function one() should have a function block scope, i can't actually get why the browser doesn't give any error when x is passed as an argument in function two().
I expected the browser to throw an error