Learn
Scope
Practice Good Scoping
- Avoid Global Variables
Global variables can lead to unexpected side effects and make code difficult to debug. Encapsulate variables within appropriate scopes to maintain control.
- Use Function Scope
Localize variables within function scopes to prevent name conflicts and encourage modular programming.
- Declare Variables Properly
Use let or const instead of var to create block-scoped variables, restricting their usage to the appropriate scope.
- Avoid Reusing Variable Names
Descriptive names that represent the purpose and context of variables prevent confusion and errors.
- Use Proper Naming Conventions
Clear and descriptive names improve readability and reduce scope-related issues.
Instructions
1.
Declare another function showLocalVar() inside the checkScope() function.
2.
Inside the showLocalVar() function, console.log the variable localVar.
3.
Call the showLocalVar() function inside checkScope() function.
Sign up to start coding
Already have an account?
Sign In
Course content
