{
  "id": 10612546,
  "title": "Hoisting in javascript",
  "url": "https://urgent.news/2026/09/29/hoisting-in-javascript",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-09-29T05:09:30.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/sajin_joe/hoisting-in-javascript-3mm0"
  },
  "original_language": "en",
  "account": "JavaScript's hoisting is the automatic behavior where variable and function declarations are moved to the top of their scope during the creation phase, before code execution. This means that all variable and function declarations are hoisted, regardless of where they are defined in the code.\n\nFunction hoisting occurs when a function is declared. For instance, when a function named greet() is declared, JavaScript automatically moves its declaration to the top of its scope. This allows the function to be called before it is defined in the code. An example of this is shown in the first point of the source material, where the function greet() is called and produces the output \"Hello Sajin\".\n\nVariable hoisting, on the other hand, is a bit different. When a variable is declared with 'var', JavaScript moves the declaration to the top of its scope, but the assignment is not moved. This means that the variable can be accessed even before it is declared, but its value will be 'undefined' until it is assigned. This behavior is illustrated in the second point of the source material, where the variable 'name' is logged before it is assigned the value \"Sajin\".\n\nVariables declared with 'let' and 'const' also undergo hoisting, but they cannot be accessed before their declaration. Similar to the 'var' keyword, their declaration is moved to the top of their scope, but their value assignment is not. This is demonstrated in the third point of the source material, where an attempt to log the value of 'name' before it is assigned results in a ReferenceError. The same principle applies to variables declared with 'const'.\n\nThe usefulness of hoisting is most evident in the case of function declarations. For example, the code can be structured so that the main logic of a function appears before its detailed implementation. The fourth point of the source material explains this with the example of a function named 'calculate', which is called before its definition. The output of 30 is produced as a result of the addition of 10 and 20 within the function. This allows developers to organize their code in a way that makes it easier to understand and maintain.",
  "summary": "Hoisting is the default behaviour of javascript where all the variable and function declarations are moved on top. 1. Function Hoisting greet (); function greet () { console . log ( \" Hello Sajin \" ); } Output: Hello Sajin This works because function declarations are hoisted. 2. var Hoisting console . log ( name ); var name = \" Sajin \" ; Output: undefined JavaScript behaves roughly like: var name…",
  "key_points": [
    "Function hoisting allows functions to be called before they are defined in the code.",
    "Variable hoisting with 'var' allows access before declaration, but 'let' and 'const' do not."
  ],
  "editors_take": "Understanding JavaScript's hoisting behavior allows developers to organize their code in a more logical and maintainable way, particularly with function declarations that can be structured and called before their detailed implementation.",
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}