Javascript assign global variable to local variable with the same name inside a function

Viewed 28
var node = someHtmlElement
function formatNode() {
   let node = node.cloneNode(true)
   // do some stuff with node
   return node
}

I would expect this function to first use global node variable then do stuff with the clone.But this throws error "Cannot access 'node' before initialization". Why can't js first use the existing global variable inside the function?

0 Answers
Related