Skip to content
Advertisement

Tag: scope

Variable Hoisting in Javascript List of Adders

I have learned the basics of variable hoisting in JavaScript, and am now trying to enhance it by doing some exercises. I’ve come across this piece of code: This code first creates an array of functions from a given list. Each function adds the same passed number (in this case 100) to a particular value of the list and prints

How to access an array from the scope of a function

I’m trying to add an element into an array with the push() method but apparently, I can’t access that array from the scope of my function. Here’s a summary of my architecture : I know for sure that the problem come from the array. When executing the code, I have an error telling me that push isn’t a propriety of

Inner function does not return changes to variable assigned in outer function

I am attempting to modify the masterCounter variable within the timeKeyAdditionCheck function. Within the timeKeyAdditionCheck function, I successfully assign a value to masterCounter, but this change is not reflected within the scope of getEventsWithTime. When timeKeyAdditionCheck is complete, the value of masterCounter returns to null. What changes do I need to make with timeKeyAdditionCheck function? Answer The reason I wasn’t

What is the purpose of the script scope?

When inspecting scopes of a function in the DevTools console I noticed a “script” scope. After a bit of research it seems to be created for let and const variables. Scopes of a function in a script without const or let variables: Scopes of a function in a script with a let variable: Yet the following prints 1 in the

Preventing auto-creation of global variables in Javascript

I just spent some time debugging a problem that boiled down to forgetting to use the var keyword in front of a new variable identifier, so Javascript was automatically creating that variable in the global scope. Is there any way to prevent this, or change the default behavior, without using a validator like JSLint? Running a validator in between writing

Advertisement