{"id":39308,"date":"2025-11-17T12:58:58","date_gmt":"2025-11-17T20:58:58","guid":{"rendered":"https:\/\/cloudinary.com\/blog\/?p=39308"},"modified":"2025-12-12T14:18:32","modified_gmt":"2025-12-12T22:18:32","slug":"what-is-hoisting-in-javascript","status":"publish","type":"post","link":"https:\/\/cloudinary.com\/blog\/questions\/what-is-hoisting-in-javascript\/","title":{"rendered":"What is Hoisting in JavaScript?"},"content":{"rendered":"\n<p>Ever seen your JavaScript log undefined for a variable that you clearly declared, or a ReferenceError pop up before a line that seems perfectly fine? Threads across dev communities often boil down to the same core concept: hoisting.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Question:<\/h2>\n\n\n\n<p><em>What is hoisting in JavaScript? I keep running into behavior I do not expect: sometimes variables are undefined instead of throwing, function declarations seem callable before I define them, and let or const variables produce temporal dead zone errors.&nbsp;<\/em><\/p>\n\n\n\n<p><em>How does hoisting actually work for var vs let\/const, function declarations vs function expressions, and classes? Also, how should I structure my code to avoid surprises in modules and real projects?<\/em><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Answer:<\/h2>\n\n\n\n<p>Hoisting is JavaScript\u2019s compile-time behavior where declarations are processed before your code executes. In practice, identifiers are known to the engine at the start of their scope, but only some get initialized right away. Understanding which parts are hoisted and how they are initialized prevents subtle bugs. Here\u2019s a breakdown:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Key Rules of Hoisting<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>var<\/code> declarations are hoisted and initialized to undefined. Accessing them before their assignment gives <code>undefined<\/code>, not a <code>ReferenceError<\/code>.<\/li>\n\n\n\n<li><code>let<\/code> and <code>const<\/code> are hoisted but not initialized. Accessing them before their declaration throws a <code>ReferenceError<\/code> due to the temporal dead zone.<\/li>\n\n\n\n<li>Function declarations are hoisted with their full body. You can call them before the line they appear on.<\/li>\n\n\n\n<li>Function expressions and arrow functions are variables. They follow <code>var<\/code> or <code>let\/const<\/code> rules depending on how you declare them.<\/li>\n\n\n\n<li>Class declarations are hoisted but remain in the temporal dead zone until evaluated.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Examples<\/h3>\n\n\n\n<p><strong>var gets hoisted and initialized to undefined<\/strong>.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript shcb-wrap-lines\"><span class=\"hljs-built_in\">console<\/span>.log(a); <span class=\"hljs-comment\">\/\/ undefined<\/span>\n<span class=\"hljs-keyword\">var<\/span> a = <span class=\"hljs-number\">42<\/span>;\n<span class=\"hljs-built_in\">console<\/span>.log(a); <span class=\"hljs-comment\">\/\/ 42<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><strong>let and const are hoisted but not initialized<\/strong>.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript shcb-wrap-lines\"><span class=\"hljs-built_in\">console<\/span>.log(b); <span class=\"hljs-comment\">\/\/ ReferenceError: Cannot access 'b' before initialization<\/span>\n<span class=\"hljs-keyword\">let<\/span> b = <span class=\"hljs-number\">1<\/span>;\n\n<span class=\"hljs-built_in\">console<\/span>.log(c); <span class=\"hljs-comment\">\/\/ ReferenceError<\/span>\n<span class=\"hljs-keyword\">const<\/span> c = <span class=\"hljs-number\">2<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><strong>Function declarations are hoisted with their body<\/strong>.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript shcb-wrap-lines\">greet(); <span class=\"hljs-comment\">\/\/ \"hi\"<\/span>\n<span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">greet<\/span>(<span class=\"hljs-params\"><\/span>) <\/span>{\n\u00a0 <span class=\"hljs-built_in\">console<\/span>.log(<span class=\"hljs-string\">\"hi\"<\/span>);\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><strong>Function expressions follow variable rules<\/strong>.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript shcb-wrap-lines\">say(); <span class=\"hljs-comment\">\/\/ TypeError: say is not a function<\/span>\n<span class=\"hljs-keyword\">var<\/span> say = <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> (<span class=\"hljs-params\"><\/span>) <\/span>{ <span class=\"hljs-built_in\">console<\/span>.log(<span class=\"hljs-string\">\"hello\"<\/span>); };\n\n<span class=\"hljs-comment\">\/\/ With let:<\/span>\n<span class=\"hljs-comment\">\/\/ say(); \/\/ ReferenceError<\/span>\n<span class=\"hljs-comment\">\/\/ let say = () =&gt; console.log(\"hello\");<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><strong>Classes are in the temporal dead zone<\/strong>.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript shcb-wrap-lines\"><span class=\"hljs-keyword\">new<\/span> Person(); <span class=\"hljs-comment\">\/\/ ReferenceError<\/span>\n<span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">Person<\/span> <\/span>{\n\u00a0 <span class=\"hljs-keyword\">constructor<\/span>() { <span class=\"hljs-keyword\">this<\/span>.name = <span class=\"hljs-string\">\"Ada\"<\/span>; }\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\">Modules and Hoisting<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>ESM imports are hoisted and evaluated before module code runs. Imports must be at the top level and cannot be conditional.<\/li>\n\n\n\n<li>Because modules run in strict mode, relying on <code>var<\/code> hoisting is even more error-prone. Use <code>let<\/code> and <code>const<\/code> instead.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Structure Your Code to Avoid Hoisting Pitfalls<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Prefer <code>const<\/code> by default, <code>let<\/code> when reassignment is needed, and avoid using <code>var<\/code>.<\/li>\n\n\n\n<li>Declare functions <em>before<\/em> using them, or use function declarations when appropriate.<\/li>\n\n\n\n<li>Keep related declarations near their usage to make initialization order obvious.<\/li>\n\n\n\n<li>Enable linter rules like <code>no-use-before-define<\/code>.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Debugging Tips<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>If you see undefined where you expected a value, check for <code>var<\/code> being read before assignment.<\/li>\n\n\n\n<li>If you see a <code>ReferenceError<\/code>, verify you are not touching <code>let<\/code>, <code>const<\/code>, or <code>class<\/code> before their declaration.<\/li>\n\n\n\n<li>In modules, ensure imports are top level and not conditionally executed.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Using Cloudinary in JS Without Hoisting Surprises<\/h3>\n\n\n\n<p>Suppose you build image URLs dynamically for delivery. Hoisting rules still apply to your helpers and config.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript shcb-wrap-lines\"><span class=\"hljs-comment\">\/\/ Bad: use before initialization causes ReferenceError with let\/const<\/span>\n<span class=\"hljs-keyword\">const<\/span> imgUrl = buildUrl(<span class=\"hljs-string\">\"sample\"<\/span>); <span class=\"hljs-comment\">\/\/ ReferenceError if buildUrl is a const below<\/span>\n<span class=\"hljs-keyword\">const<\/span> buildUrl = <span class=\"hljs-function\">(<span class=\"hljs-params\">id<\/span>) =&gt;<\/span> <span class=\"hljs-string\">`https:\/\/res.cloudinary.com\/demo\/image\/upload\/w_400,c_fill\/<span class=\"hljs-subst\">${id}<\/span>.jpg`<\/span>;\n\n<span class=\"hljs-comment\">\/\/ Good: either use a function declaration or call after definition<\/span>\n\n<span class=\"hljs-comment\">\/\/ Option A: function declaration<\/span>\n<span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">buildUrl<\/span>(<span class=\"hljs-params\">id<\/span>) <\/span>{\n\u00a0 <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-string\">`https:\/\/res.cloudinary.com\/demo\/image\/upload\/w_400,c_fill\/<span class=\"hljs-subst\">${id}<\/span>.jpg`<\/span>;\n}\n<span class=\"hljs-keyword\">const<\/span> imgUrlA = buildUrl(<span class=\"hljs-string\">\"sample\"<\/span>);\n\n<span class=\"hljs-comment\">\/\/ Option B: function expression, but call later<\/span>\n<span class=\"hljs-keyword\">const<\/span> buildUrlB = <span class=\"hljs-function\">(<span class=\"hljs-params\">id<\/span>) =&gt;<\/span> <span class=\"hljs-string\">`https:\/\/res.cloudinary.com\/demo\/image\/upload\/w_400,c_fill\/<span class=\"hljs-subst\">${id}<\/span>.jpg`<\/span>;\n<span class=\"hljs-keyword\">const<\/span> imgUrlB = buildUrlB(<span class=\"hljs-string\">\"sample\"<\/span>);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>When rendering, make sure your DOM usage is correct and accessible. If you are optimizing how images are embedded, this primer on the <a href=\"https:\/\/cloudinary.com\/guides\/image-effects\/html-image-tag\">HTML image tag<\/a> is a handy refresher. For bigger-picture delivery strategy and caching behavior, see <a href=\"https:\/\/cloudinary.com\/guides\/web-performance\/understanding-image-hosting-for-websites\">Understanding image hosting for websites<\/a>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Common Gotchas Checklist<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Reading a <code>var<\/code> before its assignment returns <code>undefined<\/code>, not a <code>ReferenceError<\/code>.<\/li>\n\n\n\n<li>Reading <code>let<\/code>, <code>const<\/code>, or <code>class<\/code> before declaration throws due to the temporal dead zone.<\/li>\n\n\n\n<li>Function declarations are callable before their appearance; function expressions are not.<\/li>\n\n\n\n<li>Imports are hoisted and must be top level in ES modules.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">TL;DR<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Hoisting makes declarations visible at the start of their scope, but only <code>var<\/code> gets initialized to <code>undefined<\/code>.<\/li>\n\n\n\n<li>Use <code>const<\/code> and <code>let<\/code>, declare functions before use, and avoid relying on hoisting for control flow.<\/li>\n\n\n\n<li>In real apps, especially when building URLs or helpers for media delivery, ensure functions and config are defined before you use them.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Learn More<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/cloudinary.com\/tools\/png-to-webp\">PNG to WebP Converter<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/cloudinary.com\/tools\/image-to-jpg\">Image to JPG Converter<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/cloudinary.com\/tools\/image-upscale\">Image Upscale<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/cloudinary.com\/guides\/video\/video-engineering\">Video Engineering Guide<\/a><\/li>\n<\/ul>\n\n\n\n<p>Ready to optimize how you manage and deliver media in your JavaScript apps? <a href=\"https:\/\/cloudinary.com\/users\/register_free\">Sign up for Cloudinary<\/a> and streamline your asset workflow with powerful transformations and fast delivery.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ever seen your JavaScript log undefined for a variable that you clearly declared, or a ReferenceError pop up before a line that seems perfectly fine? Threads across dev communities often boil down to the same core concept: hoisting. Question: What is hoisting in JavaScript? I keep running into behavior I do not expect: sometimes variables [&hellip;]<\/p>\n","protected":false},"author":88,"featured_media":39267,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_cloudinary_featured_overwrite":false,"footnotes":""},"categories":[1],"tags":[423],"class_list":["post-39308","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","tag-questions"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.6 (Yoast SEO v26.9) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>What is Hoisting in JavaScript?<\/title>\n<meta name=\"description\" content=\"Ever seen your JavaScript log undefined for a variable that you clearly declared, or a ReferenceError pop up before a line that seems perfectly fine?\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/cloudinary.com\/blog\/questions\/what-is-hoisting-in-javascript\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"What is Hoisting in JavaScript?\" \/>\n<meta property=\"og:description\" content=\"Ever seen your JavaScript log undefined for a variable that you clearly declared, or a ReferenceError pop up before a line that seems perfectly fine?\" \/>\n<meta property=\"og:url\" content=\"https:\/\/cloudinary.com\/blog\/questions\/what-is-hoisting-in-javascript\/\" \/>\n<meta property=\"og:site_name\" content=\"Cloudinary Blog\" \/>\n<meta property=\"article:published_time\" content=\"2025-11-17T20:58:58+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-12-12T22:18:32+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1763149247\/QA_javascript_featured_image\/QA_javascript_featured_image.jpg?_i=AA\" \/>\n\t<meta property=\"og:image:width\" content=\"1999\" \/>\n\t<meta property=\"og:image:height\" content=\"1100\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"damjanantevski\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"NewsArticle\",\"@id\":\"https:\/\/cloudinary.com\/blog\/questions\/what-is-hoisting-in-javascript\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/questions\/what-is-hoisting-in-javascript\/\"},\"author\":{\"name\":\"damjanantevski\",\"@id\":\"https:\/\/cloudinary.com\/blog\/#\/schema\/person\/43592e43c12520a1e867d456b1e8cf7e\"},\"headline\":\"What is Hoisting in JavaScript?\",\"datePublished\":\"2025-11-17T20:58:58+00:00\",\"dateModified\":\"2025-12-12T22:18:32+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/questions\/what-is-hoisting-in-javascript\/\"},\"wordCount\":621,\"publisher\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/questions\/what-is-hoisting-in-javascript\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1763149247\/QA_javascript_featured_image\/QA_javascript_featured_image.jpg?_i=AA\",\"keywords\":[\"Questions\"],\"inLanguage\":\"en-US\",\"copyrightYear\":\"2025\",\"copyrightHolder\":{\"@id\":\"https:\/\/cloudinary.com\/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/cloudinary.com\/blog\/questions\/what-is-hoisting-in-javascript\/\",\"url\":\"https:\/\/cloudinary.com\/blog\/questions\/what-is-hoisting-in-javascript\/\",\"name\":\"What is Hoisting in JavaScript?\",\"isPartOf\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/questions\/what-is-hoisting-in-javascript\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/questions\/what-is-hoisting-in-javascript\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1763149247\/QA_javascript_featured_image\/QA_javascript_featured_image.jpg?_i=AA\",\"datePublished\":\"2025-11-17T20:58:58+00:00\",\"dateModified\":\"2025-12-12T22:18:32+00:00\",\"description\":\"Ever seen your JavaScript log undefined for a variable that you clearly declared, or a ReferenceError pop up before a line that seems perfectly fine?\",\"breadcrumb\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/questions\/what-is-hoisting-in-javascript\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/cloudinary.com\/blog\/questions\/what-is-hoisting-in-javascript\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/cloudinary.com\/blog\/questions\/what-is-hoisting-in-javascript\/#primaryimage\",\"url\":\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1763149247\/QA_javascript_featured_image\/QA_javascript_featured_image.jpg?_i=AA\",\"contentUrl\":\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1763149247\/QA_javascript_featured_image\/QA_javascript_featured_image.jpg?_i=AA\",\"width\":1999,\"height\":1100},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/cloudinary.com\/blog\/questions\/what-is-hoisting-in-javascript\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/cloudinary.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"What is Hoisting in JavaScript?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/cloudinary.com\/blog\/#website\",\"url\":\"https:\/\/cloudinary.com\/blog\/\",\"name\":\"Cloudinary Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/cloudinary.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/cloudinary.com\/blog\/#organization\",\"name\":\"Cloudinary Blog\",\"url\":\"https:\/\/cloudinary.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/cloudinary.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1649718331\/Web_Assets\/blog\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877.png?_i=AA\",\"contentUrl\":\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1649718331\/Web_Assets\/blog\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877.png?_i=AA\",\"width\":312,\"height\":60,\"caption\":\"Cloudinary Blog\"},\"image\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/cloudinary.com\/blog\/#\/schema\/person\/43592e43c12520a1e867d456b1e8cf7e\",\"name\":\"damjanantevski\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/cloudinary.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/3b40c995531fe4d510212a06c9d4fc666d2cb8efbfebc98a94191701accf4817?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/3b40c995531fe4d510212a06c9d4fc666d2cb8efbfebc98a94191701accf4817?s=96&d=mm&r=g\",\"caption\":\"damjanantevski\"}}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"What is Hoisting in JavaScript?","description":"Ever seen your JavaScript log undefined for a variable that you clearly declared, or a ReferenceError pop up before a line that seems perfectly fine?","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/cloudinary.com\/blog\/questions\/what-is-hoisting-in-javascript\/","og_locale":"en_US","og_type":"article","og_title":"What is Hoisting in JavaScript?","og_description":"Ever seen your JavaScript log undefined for a variable that you clearly declared, or a ReferenceError pop up before a line that seems perfectly fine?","og_url":"https:\/\/cloudinary.com\/blog\/questions\/what-is-hoisting-in-javascript\/","og_site_name":"Cloudinary Blog","article_published_time":"2025-11-17T20:58:58+00:00","article_modified_time":"2025-12-12T22:18:32+00:00","og_image":[{"width":1999,"height":1100,"url":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1763149247\/QA_javascript_featured_image\/QA_javascript_featured_image.jpg?_i=AA","type":"image\/jpeg"}],"author":"damjanantevski","twitter_card":"summary_large_image","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"NewsArticle","@id":"https:\/\/cloudinary.com\/blog\/questions\/what-is-hoisting-in-javascript\/#article","isPartOf":{"@id":"https:\/\/cloudinary.com\/blog\/questions\/what-is-hoisting-in-javascript\/"},"author":{"name":"damjanantevski","@id":"https:\/\/cloudinary.com\/blog\/#\/schema\/person\/43592e43c12520a1e867d456b1e8cf7e"},"headline":"What is Hoisting in JavaScript?","datePublished":"2025-11-17T20:58:58+00:00","dateModified":"2025-12-12T22:18:32+00:00","mainEntityOfPage":{"@id":"https:\/\/cloudinary.com\/blog\/questions\/what-is-hoisting-in-javascript\/"},"wordCount":621,"publisher":{"@id":"https:\/\/cloudinary.com\/blog\/#organization"},"image":{"@id":"https:\/\/cloudinary.com\/blog\/questions\/what-is-hoisting-in-javascript\/#primaryimage"},"thumbnailUrl":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1763149247\/QA_javascript_featured_image\/QA_javascript_featured_image.jpg?_i=AA","keywords":["Questions"],"inLanguage":"en-US","copyrightYear":"2025","copyrightHolder":{"@id":"https:\/\/cloudinary.com\/#organization"}},{"@type":"WebPage","@id":"https:\/\/cloudinary.com\/blog\/questions\/what-is-hoisting-in-javascript\/","url":"https:\/\/cloudinary.com\/blog\/questions\/what-is-hoisting-in-javascript\/","name":"What is Hoisting in JavaScript?","isPartOf":{"@id":"https:\/\/cloudinary.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/cloudinary.com\/blog\/questions\/what-is-hoisting-in-javascript\/#primaryimage"},"image":{"@id":"https:\/\/cloudinary.com\/blog\/questions\/what-is-hoisting-in-javascript\/#primaryimage"},"thumbnailUrl":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1763149247\/QA_javascript_featured_image\/QA_javascript_featured_image.jpg?_i=AA","datePublished":"2025-11-17T20:58:58+00:00","dateModified":"2025-12-12T22:18:32+00:00","description":"Ever seen your JavaScript log undefined for a variable that you clearly declared, or a ReferenceError pop up before a line that seems perfectly fine?","breadcrumb":{"@id":"https:\/\/cloudinary.com\/blog\/questions\/what-is-hoisting-in-javascript\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/cloudinary.com\/blog\/questions\/what-is-hoisting-in-javascript\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cloudinary.com\/blog\/questions\/what-is-hoisting-in-javascript\/#primaryimage","url":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1763149247\/QA_javascript_featured_image\/QA_javascript_featured_image.jpg?_i=AA","contentUrl":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1763149247\/QA_javascript_featured_image\/QA_javascript_featured_image.jpg?_i=AA","width":1999,"height":1100},{"@type":"BreadcrumbList","@id":"https:\/\/cloudinary.com\/blog\/questions\/what-is-hoisting-in-javascript\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/cloudinary.com\/blog\/"},{"@type":"ListItem","position":2,"name":"What is Hoisting in JavaScript?"}]},{"@type":"WebSite","@id":"https:\/\/cloudinary.com\/blog\/#website","url":"https:\/\/cloudinary.com\/blog\/","name":"Cloudinary Blog","description":"","publisher":{"@id":"https:\/\/cloudinary.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/cloudinary.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/cloudinary.com\/blog\/#organization","name":"Cloudinary Blog","url":"https:\/\/cloudinary.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cloudinary.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1649718331\/Web_Assets\/blog\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877.png?_i=AA","contentUrl":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1649718331\/Web_Assets\/blog\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877.png?_i=AA","width":312,"height":60,"caption":"Cloudinary Blog"},"image":{"@id":"https:\/\/cloudinary.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/cloudinary.com\/blog\/#\/schema\/person\/43592e43c12520a1e867d456b1e8cf7e","name":"damjanantevski","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cloudinary.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/3b40c995531fe4d510212a06c9d4fc666d2cb8efbfebc98a94191701accf4817?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/3b40c995531fe4d510212a06c9d4fc666d2cb8efbfebc98a94191701accf4817?s=96&d=mm&r=g","caption":"damjanantevski"}}]}},"jetpack_featured_media_url":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1763149247\/QA_javascript_featured_image\/QA_javascript_featured_image.jpg?_i=AA","_links":{"self":[{"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/posts\/39308","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/users\/88"}],"replies":[{"embeddable":true,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/comments?post=39308"}],"version-history":[{"count":2,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/posts\/39308\/revisions"}],"predecessor-version":[{"id":39608,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/posts\/39308\/revisions\/39608"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/media\/39267"}],"wp:attachment":[{"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/media?parent=39308"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/categories?post=39308"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/tags?post=39308"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}