The following piece of javascript code:
function init(name) {
  function displayName() {
    var name = name || "default string";
    console.log(name); 
  }
  displayName();
}
init("parameter string"); //here is unexpected ouput: "default string"
Why does the above code not output "parameter string" as expected?
Thanks in advance.
update: However, the following code works as expected:
function init(name) {
  var name = name||"Mozilla";
  console.log("init name:",name)
}
init("param string")//output: "init name: param string" as expected
what's the different between the two codes?
 
     
    