+ 7
You are running your code before DOM is created. Try running your code in a window.onload function,
like below:
window.onload = function(){
var Start="Gyu";
var Star=Start.substring(0,1);
var Fir=document.getElementById("A");
Fir.innerHTML=Star;
}
+ 5
It means document.getElementById("A") is being called before the div is even created. window.onload function will wait till all the DOM elements i.e. html elements are constructed and then it will executed the code block.
+ 2
SoloLearn detail: The [JS] tab is inserted into <head> and starts running before <body> is parsed.
Some people put <script> at the end of <body> -- I did this to be more clear -- but the event-driven approach (onload) is the better one.