Topics: Blocks and Scope , Global Scope , Block Scope , Scope Pollution , Practice Good Scoping
- Create a html file with your name like john.html
- Add current code to that file:
<!DOCTYPE html>
<html>
<body>
<script>
// your code here
</script>
</body>
</html>-
Define a global variable named
colorwithconstand set it toblue -
Declare a function named
logColor1without parameter and logcolorvariable into console. -
Declare a function named
logColor2with a parameter namedcolorand logcolorvariable into console. -
Call function
logColor2with'red'as argument and check the result. -
Declare a function named
logColor3with a parameter namedcolorand logcolorvariable into console. -
In this function, add an if statement before
console.logthat checkcoloris green. If it is green useletto define a variable namedcolorand set itlight green, thenconsole.log(color) -
Call function
logColor3with'green'as argument and check the result. -
Analyze and discuss the behaviour of scoping in all steps.
Send Pull Request. Check how to deliver your code: https://codingwithbasir.com/how-to-deliver-projects/
Download Learn JavaScript eBook from https://codingwithbasir.com/learn-javascript
