---
title: "Meaning & Key Takeaway of: JavaScript creates all local variables at…"
description: "\"“JavaScript creates all local variables at the beginning of a function whether you declare them or not (this is called “hoisting” and we’ll come back t..."
image: "https://sms4smile.com/quotes/i/d1c/eric-freeman-7573_quote_javascript-creates-all-local-variables-a_880658.jpg"
---

#  JavaScript creates all local variables at the beginning of…

![“JavaScript creates all local variables at the beginning of a function whether you declare them or not (this is called “hoisting” and we’ll come back to it later), but the variables are all undefined until they are assigned a value, which might not be what you want.” quote by Eric Freeman](https://sms4smile.com/quotes/i/d1c/eric-freeman-7573_quote_javascript-creates-all-local-variables-a_880658.jpg)   [Download](https://sms4smile.com/quotes/i/d1c/eric-freeman-7573_quote_javascript-creates-all-local-variables-a_880658.jpg) [Open image](https://sms4smile.com/quotes/i/d1c/eric-freeman-7573_quote_javascript-creates-all-local-variables-a_880658.jpg)

> ““JavaScript creates all local variables at the beginning of a function whether you declare them or not (this is called “hoisting” and we’ll come back to it later), but the variables are all undefined until they are assigned a value, which might not be what you want.””

[Eric Freeman](https://sms4smile.com/quotes/author/eric-freeman/)

## About This Quote

This interpretation was drafted with AI assistance. It is one reading of the quote, not the author's own explanation.

Hoisting moves variable declarations to the top of a function, leaving them undefined until assigned, which can cause unexpected behavior.

**In simple terms:** Variables are declared early but stay empty until set.

Key Takeaway

Be aware of hoisting to avoid bugs.

Themes

programming JavaScript variables

Mood

technical educational

Type

instructional technical

When to use this quote

- debugging
- code reviews
- learning JavaScript
- teaching beginners

Key Concepts

hoisting scope initialization

Questions to Reflect On

- How does hoisting affect function execution?
- What strategies prevent hoisting errors?

A Different Perspective

Hoisting can hide bugs if not understood.

★ ★ ★ ★ ★   No ratings yet

[Technology](https://sms4smile.com/quotes/about/technology/)

## Related quotes

> [“Go does not permit unused local variables, so this would result in a compilation error.”](https://sms4smile.com/quotes/alan-a-a-donovan/go-does-not-permit-unused-local-variables-so-this-would-result-in-a/)

Alan A. A. Donovan

> [There's a story about how the program is organized, there's a story about the context in which the program is expected to operate. And…](https://sms4smile.com/quotes/guy-steele/there-s-a-story-about-how-the-program-is-organized-there-s-a-story/)

[Guy Steele](https://sms4smile.com/quotes/author/guy-steele/)

> [“Web Workers have a global function named importScripts that you can use to import one or more JavaScript files into your worker. To”](https://sms4smile.com/quotes/eric-freeman/web-workers-have-a-global-function-named-importscripts-that-you-can/)

[Eric Freeman](https://sms4smile.com/quotes/author/eric-freeman/)

> [“when you assign a value to a variable name that hasn’t been previously declared, it is treated as a new, global variable. So be…](https://sms4smile.com/quotes/eric-freeman/when-you-assign-a-value-to-a-variable-name-that-hasn-t-been/)

[Eric Freeman](https://sms4smile.com/quotes/author/eric-freeman/)

> [“the constructor always has a prototype property. More”](https://sms4smile.com/quotes/eric-freeman/the-constructor-always-has-a-prototype-property-more/)

[Eric Freeman](https://sms4smile.com/quotes/author/eric-freeman/)

> [Change is one of the scariest things in the world and yet it is also one of those variables of human existence that no…](https://sms4smile.com/quotes/aberjhani/change-is-one-of-the-scariest-things-in-the-world-and-yet-it-is-also/)

[Aberjhani](https://sms4smile.com/quotes/author/aberjhani/)

> [“With great goals, comes the high costs; both fixed and variable. Time is the fixed cost; efforts, variable. Spend passionately.”](https://sms4smile.com/quotes/vikrmn-ca-vikram-verma/with-great-goals-comes-the-high-costs-both-fixed-and-variable-time-is/)

[Vikrmn: CA Vikram Verma](https://sms4smile.com/quotes/author/vikrmn-ca-vikram-verma/)

> [I believe that it may be normal, healthy, and even productive to experience mild to moderate depression from time to time as part of…](https://sms4smile.com/quotes/andrew-weil/i-believe-that-it-may-be-normal-healthy-and-even-productive-to/)

[Andrew Weil](https://sms4smile.com/quotes/author/andrew-weil/)

> [We’re never gonna understand women. They’re way too complex. You’ve got too many variables to consider. PMS, bad hair days, miscellaneous mood swings .…](https://sms4smile.com/quotes/susane-colasanti/we-re-never-gonna-understand-women-they-re-way-too-complex-you-ve-got/)

[Susane Colasanti](https://sms4smile.com/quotes/author/susane-colasanti/)

> [Because what happens is, as the economy suffers, tax revenues go down. But unlike businesses, where at least your variable costs go down, in…](https://sms4smile.com/quotes/meg-whitman/because-what-happens-is-as-the-economy-suffers-tax-revenues-go-down/)

[Meg Whitman](https://sms4smile.com/quotes/author/meg-whitman/)

> [The difference is that we have the hardest and most painful evidence that there was a Holocaust. But, for the global warming scenario that…](https://sms4smile.com/quotes/thomas-sowell/the-difference-is-that-we-have-the-hardest-and-most-painful-evidence/)

[Thomas Sowell](https://sms4smile.com/quotes/author/thomas-sowell/)

> [“You should imagine variables as tentacles, rather than boxes. They do not contain values; they grasp them—two variables can refer to the same value.”](https://sms4smile.com/quotes/marijn-haverbeke/you-should-imagine-variables-as-tentacles-rather-than-boxes-they-do/)

[Marijn Haverbeke](https://sms4smile.com/quotes/author/marijn-haverbeke/)

> [Science manipulates things and gives up living in them. It makes its own limited models of things; operating upon these indices or variables to…](https://sms4smile.com/quotes/maurice-merleau-ponty/science-manipulates-things-and-gives-up-living-in-them-it-makes-its/)

[Maurice Merleau-Ponty](https://sms4smile.com/quotes/author/maurice-merleau-ponty/)

> [As a social and as a personal force, religion has become a dependent variable. It does not originate; it reacts. It does not denounce;…](https://sms4smile.com/quotes/c-wright-mills/as-a-social-and-as-a-personal-force-religion-has-become-a-dependent/)

[C. Wright Mills](https://sms4smile.com/quotes/author/c-wright-mills/)

> [As the variable capital always stays in the hands of the capitalist in some form or other, it cannot be claimed in any way…](https://sms4smile.com/quotes/karl-marx/as-the-variable-capital-always-stays-in-the-hands-of-the-capitalist/)

[Karl Marx](https://sms4smile.com/quotes/author/karl-marx/)

## More by Eric Freeman

> [“When you delete a property, you’re not just deleting the value of the property, you’re deleting the property itself. And, if you try to…](https://sms4smile.com/quotes/eric-freeman/when-you-delete-a-property-you-re-not-just-deleting-the-value-of-the/)

[Eric Freeman](https://sms4smile.com/quotes/author/eric-freeman/)

> [“the constructor always has a prototype property. More”](https://sms4smile.com/quotes/eric-freeman/the-constructor-always-has-a-prototype-property-more/)

[Eric Freeman](https://sms4smile.com/quotes/author/eric-freeman/)

> [“when you assign a value to a variable name that hasn’t been previously declared, it is treated as a new, global variable. So be…](https://sms4smile.com/quotes/eric-freeman/when-you-assign-a-value-to-a-variable-name-that-hasn-t-been/)

[Eric Freeman](https://sms4smile.com/quotes/author/eric-freeman/)

> [“Web Workers have a global function named importScripts that you can use to import one or more JavaScript files into your worker. To”](https://sms4smile.com/quotes/eric-freeman/web-workers-have-a-global-function-named-importscripts-that-you-can/)

[Eric Freeman](https://sms4smile.com/quotes/author/eric-freeman/)

> [“If the two values have different types, try to convert them into the same type and then compare them”](https://sms4smile.com/quotes/eric-freeman/if-the-two-values-have-different-types-try-to-convert-them-into-the/)

[Eric Freeman](https://sms4smile.com/quotes/author/eric-freeman/)

> [“Well, it’s a browser policy, and it says you can’t retrieve data from a domain that is different from the domain the page itself…](https://sms4smile.com/quotes/eric-freeman/well-it-s-a-browser-policy-and-it-says-you-can-t-retrieve-data-from-a/)

[Eric Freeman](https://sms4smile.com/quotes/author/eric-freeman/)

> [“Math is not a constructor, or even a function. It’s an object. As you know, Math is a built-in object that you can use…](https://sms4smile.com/quotes/eric-freeman/math-is-not-a-constructor-or-even-a-function-it-s-an-object-as-you/)

[Eric Freeman](https://sms4smile.com/quotes/author/eric-freeman/)

> [“When you pass zero to setTimeout, you’re asking JavaScript to run your timeout handler as soon as it possibly can — and this leads…](https://sms4smile.com/quotes/eric-freeman/when-you-pass-zero-to-settimeout-you-re-asking-javascript-to-run-your/)

[Eric Freeman](https://sms4smile.com/quotes/author/eric-freeman/)

> [“JavaScript doesn’t have a character type. So characters are returned as new strings containing one character.”](https://sms4smile.com/quotes/eric-freeman/javascript-doesn-t-have-a-character-type-so-characters-are-returned/)

[Eric Freeman](https://sms4smile.com/quotes/author/eric-freeman/)

> [“Closures are often used to capture state for event handlers.”](https://sms4smile.com/quotes/eric-freeman/closures-are-often-used-to-capture-state-for-event-handlers/)

[Eric Freeman](https://sms4smile.com/quotes/author/eric-freeman/)

> [“Lexical scope means that we can determine the scope of a variable by reading our code.”](https://sms4smile.com/quotes/eric-freeman/lexical-scope-means-that-we-can-determine-the-scope-of-a-variable-by/)

[Eric Freeman](https://sms4smile.com/quotes/author/eric-freeman/)

> [“Q: Q: You said getElementsByTagName returns a list. Do you mean an array? A: A: It returns an object that you can treat like…](https://sms4smile.com/quotes/eric-freeman/q-q-you-said-getelementsbytagname-returns-a-list-do-you-mean-an-array/)

[Eric Freeman](https://sms4smile.com/quotes/author/eric-freeman/)

> [“the truth is JavaScript actually makes two passes over your page: in the first pass it reads all the function definitions, and in the…](https://sms4smile.com/quotes/eric-freeman/the-truth-is-javascript-actually-makes-two-passes-over-your-page-in/)

[Eric Freeman](https://sms4smile.com/quotes/author/eric-freeman/)

> [“If you change any property in the prototype, it affects all the objects that inherit from that prototype, unless that object has overridden that…](https://sms4smile.com/quotes/eric-freeman/if-you-change-any-property-in-the-prototype-it-affects-all-the/)

[Eric Freeman](https://sms4smile.com/quotes/author/eric-freeman/)

> [“methods in objects are properties too. They just happen to have a function assigned to them.”](https://sms4smile.com/quotes/eric-freeman/methods-in-objects-are-properties-too-they-just-happen-to-have-a/)

[Eric Freeman](https://sms4smile.com/quotes/author/eric-freeman/)

[Explore all 90 Eric Freeman quotes ](https://sms4smile.com/quotes/author/eric-freeman/)

## More Technology quotes

> [But we are convinced that if we are to play a meaningful role nationally, and in the community of nations, we must be second…](https://sms4smile.com/quotes/vikram-sarabhai/but-we-are-convinced-that-if-we-are-to-play-a-meaningful-role/)

[Vikram Sarabhai](https://sms4smile.com/quotes/author/vikram-sarabhai/)

> [“This story is not at all an uncommon one in tech circles, including gaming. The popular notion is that women who get ahead must…](https://sms4smile.com/quotes/bailey-poland/this-story-is-not-at-all-an-uncommon-one-in-tech-circles-including/)

[Bailey Poland](https://sms4smile.com/quotes/author/bailey-poland/)

> [The time that one gains cannot be accumulated in a storehouse; it is contradictory to want to save up existence, which, the fact is,…](https://sms4smile.com/quotes/simone-de-beauvoir/the-time-that-one-gains-cannot-be-accumulated-in-a-storehouse-it-is/)

[Simone de Beauvoir](https://sms4smile.com/quotes/author/simone-de-beauvoir/)

> [“The metaprogrammer who uses one, or especially several, applications as components in a larger system. This is the user whose needs are poorly met…](https://sms4smile.com/quotes/frederick-p-brooks-jr/the-metaprogrammer-who-uses-one-or-especially-several-applications-as/)

[Frederick P. Brooks Jr](https://sms4smile.com/quotes/author/frederick-p-brooks-jr/)

> [Advances in technology will continue to reach far into every sector of our economy. Future job and economic growth in industry, defense, transportation, agriculture,…](https://sms4smile.com/quotes/christopher-bond/advances-in-technology-will-continue-to-reach-far-into-every-sector/)

[Christopher Bond](https://sms4smile.com/quotes/author/christopher-bond/)

> [“Economic growth continued by means of a succession of new products which found growing and ultimately massive demand. Some of the new products were…](https://sms4smile.com/quotes/edward-a-hudson/economic-growth-continued-by-means-of-a-succession-of-new-products/)

[Edward A. Hudson](https://sms4smile.com/quotes/author/edward-a-hudson/)

> [I had an idea for a technologically advanced luxury watch. I got involved in digital art and neon painting and put on shows of…](https://sms4smile.com/quotes/giorgio-moroder/i-had-an-idea-for-a-technologically-advanced-luxury-watch-i-got/)

[Giorgio Moroder](https://sms4smile.com/quotes/author/giorgio-moroder/)

> [What it comes down to for me is this: Will the technologies of communication in our culture, serve to enlighten us and help us…](https://sms4smile.com/quotes/roger-waters/what-it-comes-down-to-for-me-is-this-will-the-technologies-of/)

[Roger Waters](https://sms4smile.com/quotes/author/roger-waters/)

> [The display is the computer.](https://sms4smile.com/quotes/jen-hsun-huang/the-display-is-the-computer/)

Jen-Hsun Huang

> [We became Homo sapiens not that long ago, from the scientific perspective, and we've retained a lot of our beast nature. We've done all…](https://sms4smile.com/quotes/wangechi-mutu/we-became-homo-sapiens-not-that-long-ago-from-the-scientific/)

[Wangechi Mutu](https://sms4smile.com/quotes/author/wangechi-mutu/)

> [The reason that Apple is able to create products like iPad is because we always try to be at the intersection of technology and…](https://sms4smile.com/quotes/steve-jobs/the-reason-that-apple-is-able-to-create-products-like-ipad-is-because/)

[Steve Jobs](https://sms4smile.com/quotes/author/steve-jobs/)

> [I just feel like everybody stays on their phone nowadays. People will go to a party and everybody is on their phone, and you…](https://sms4smile.com/quotes/snow-tha-product/i-just-feel-like-everybody-stays-on-their-phone-nowadays-people-will/)

[Snow Tha Product](https://sms4smile.com/quotes/author/snow-tha-product/)

> [“If Amazon’s dream of a world without gatekeepers becomes reality, then the company itself will become a powerful gatekeeper.”](https://sms4smile.com/quotes/evgeny-morozov/if-amazon-s-dream-of-a-world-without-gatekeepers-becomes-reality-then/)

[Evgeny Morozov](https://sms4smile.com/quotes/author/evgeny-morozov/)

> [Real breakthroughs are not found because you want to develop some new technology, but because you are curious and want to find out how…](https://sms4smile.com/quotes/anton-zeilinger/real-breakthroughs-are-not-found-because-you-want-to-develop-some-new/)

[Anton Zeilinger](https://sms4smile.com/quotes/author/anton-zeilinger/)

> [The most fundamental question we can ever ask ourselves is whether or not the universe we live in is friendly or hostile.](https://sms4smile.com/quotes/albert-einstein/the-most-fundamental-question-we-can-ever-ask-ourselves-is-whether-or/)

[Albert Einstein](https://sms4smile.com/quotes/author/albert-einstein/)

[Browse all 18,164 Technology quotes ](https://sms4smile.com/quotes/about/technology/)

```json
{
    "@context": "https://schema.org",
    "@graph": [
        {
            "@type": "Quotation",
            "text": "“JavaScript creates all local variables at the beginning of a function whether you declare them or not (this is called “hoisting” and we’ll come back to it later), but the variables are all undefined until they are assigned a value, which might not be what you want.”",
            "creator": {
                "@type": "Person",
                "name": "Eric Freeman"
            },
            "isPartOf": {
                "@id": "https://sms4smile.com/quotes/#website"
            },
            "url": "https://sms4smile.com/quotes/eric-freeman/javascript-creates-all-local-variables-at-the-beginning-of-a-function/",
            "about": {
                "@type": "Thing",
                "name": "Technology"
            },
            "@id": "https://sms4smile.com/quotes/eric-freeman/javascript-creates-all-local-variables-at-the-beginning-of-a-function/#quotation",
            "image": {
                "@type": "ImageObject",
                "@id": "https://sms4smile.com/quotes/i/d1c/eric-freeman-7573_quote_javascript-creates-all-local-variables-a_880658.jpg",
                "contentUrl": "https://sms4smile.com/quotes/i/d1c/eric-freeman-7573_quote_javascript-creates-all-local-variables-a_880658.jpg",
                "url": "https://sms4smile.com/quotes/i/d1c/eric-freeman-7573_quote_javascript-creates-all-local-variables-a_880658.jpg",
                "width": 1080,
                "height": 1080,
                "caption": "“JavaScript creates all local variables at the beginning of a function whether you declare them or not (this…” — Eric Freeman",
                "creditText": "SMS4Smile Quotes",
                "creator": {
                    "@id": "https://sms4smile.com/quotes/#organization"
                }
            }
        },
        {
            "@type": "BreadcrumbList",
            "itemListElement": [
                {
                    "@type": "ListItem",
                    "position": 1,
                    "name": "Home",
                    "item": "https://sms4smile.com/"
                },
                {
                    "@type": "ListItem",
                    "position": 2,
                    "name": "Quotes",
                    "item": "https://sms4smile.com/quotes/"
                },
                {
                    "@type": "ListItem",
                    "position": 3,
                    "name": "Eric Freeman",
                    "item": "https://sms4smile.com/quotes/author/eric-freeman/"
                },
                {
                    "@type": "ListItem",
                    "position": 4,
                    "name": "“JavaScript creates all local variables at...",
                    "item": "https://sms4smile.com/quotes/eric-freeman/javascript-creates-all-local-variables-at-the-beginning-of-a-function/"
                }
            ],
            "@id": "https://sms4smile.com/quotes/eric-freeman/javascript-creates-all-local-variables-at-the-beginning-of-a-function/#breadcrumb"
        },
        {
            "@type": "WebSite",
            "@id": "https://sms4smile.com/quotes/#website",
            "name": "SMS4Smile Quotes",
            "url": "https://sms4smile.com/quotes/",
            "publisher": {
                "@id": "https://sms4smile.com/quotes/#organization"
            }
        },
        {
            "@type": "Organization",
            "@id": "https://sms4smile.com/quotes/#organization",
            "name": "SMS4Smile Quotes",
            "url": "https://sms4smile.com/quotes/",
            "logo": {
                "@type": "ImageObject",
                "url": "https://sms4smile.com/quotes/wp-content/themes/sq/assets/icons/icon-512.png",
                "width": 512,
                "height": 512
            }
        }
    ]
}
```
