dimanche 3 septembre 2017

Global and local variables with the same name in Javascript

I have an HTML file test.html where I have two variables both named location, one global and one local. But when I open it in browser it just said Your file was not found, and the address bar shows file://Los%20Angeles instead of file://test.html as expected. Why?

<html>
<body>
<script type="text/javascript">
var location = "Los Angeles"
function showLocation() {
    var location = "San Francisco"
    document.write(location)
}
</script>
<input type="button" onclick="showLocation()" value="Show Location"/>
</body>
</html>




Aucun commentaire:

Enregistrer un commentaire