Week 7 Example 1 Scope
001 002 function createNodeWithText(newNodeType, newNodeText) 003 { 004 // fuunctionVariable is not available in the global scope 005 functionVariable = 23; 006 // globalVariable exists here as well 007 for(let index = 0; index < globalVariable; index++) 008 { 009 // index variable only exists in the loop 010 // function variable also exists here 011 // global variable also exists here 012 console.log(index); 013 } 014 const newNode = document.createElement(newNodeType); // Create a new LI node 015 const newText = document.createTextNode(newNodeText); // Create a new text node 016 newNode.appendChild(newText); // Append text node to LI node 017 return newNode; 018 } 019 020 let globalVariable = 8; 021 const newParaNode = createNodeWithText('p','Hello world'); 022