A newbie learning javascript :)
This is my html page and the associated js code
<!DOCTYPE html>
<html>
<head>
<title> A Basic Function </title>
<link rel="stylesheet" href="css/c03.css" />
</head>
<body>
<h1>Travelworth</h1>
<div id="message">Welcome to our site!</div>
<script src="js/basic-function.js"></script>
</body>
</html>
basic-function.js
var msg="A New Message"; //Line 1
var msg="A Second Message";//Line 2
function updatemessage()
{
var e = document.getElementById('message');
e.textContent = msg;
}
updatemessage();
Q1:-
This webpage displays the message from the Line2 instead of Line1.
I am guessing this is because the "msg" variable declared in Line 2 is considered the "latest" and the interpreter has proceeded with that.
Is my assumption right ?
Q2:-
If that is the case, then there will be instances where a webpage may utilize multiple js files written by different people.
How the naming conflict will be handled on global variables between these two different js files referenced in the same webpage ?
Can someone explain ?