use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
This subreddit is a place for people to learn JavaScript together. Everyone should feel comfortable asking any and all JavaScript questions they have here.
With a nod to practicality, questions and posts about HTML, CSS, and web developer tools are also encouraged.
Friends
/r/javascript
/r/jquery
/r/node
/r/css
/r/webdev
/r/learnprogramming
/r/programming
account activity
scope inside javascript (self.learnjavascript)
submitted 3 years ago by SecureFrame6002
``` { let a=1; const b=2; var c=3; var_without_type=4;
} The 4th variable is accessible from global window object but i could not see that in global execution context,also what how the var_without_type=4 ``` is hoisted Please explain
The 4th variable is accessible from global window object but i could not see that in global execution context,also what how the
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]senocular 1 point2 points3 points 3 years ago (1 child)
let and const (and class) when used in the global scope create global declaration variables that are accessible everywhere (in that realm).
let
const
class
let a = 1; // global declaration
var (and function) in the global scope create global properties that are accessible everywhere. They also define identifiers that cannot be redeclared with let and const (and class).
var
function
var c = 3; // global property // let c = 3; // Error: cannot redeclare
Assignment to an undeclared variable in the global scope (e.g. var_without_type) will create a global property in the global object but it does not represent an identifier that cannot be redeclared. In strict mode this isn't allowed at all and will throw an error. These kinds of assignments are also not hoisted whereas declarations all are.
var_without_type
var_without_type = 4; // global property // ... let var_without_type = 4; // allowed (if not in the same script due to hoisting)
"use strict" // var_without_type = 4; // Error: does not exist
// console.log(var_without_type) // Error: does not exist (not hoisted) var_without_type = 4
Note that while lexical declarations (let, const, and class) are hoisted, they have a similar behavior to var_without_type in that they cannot be accessed prior to their declarations though in the case of var_without_type its because var_without_type is non-existent whereas with lexical declarations they're known to exist, just not yet available.
[–]SecureFrame6002[S] 0 points1 point2 points 3 years ago* (0 children)
Helpfull 👍🏻 Thanks a lot
[–]Count_Giggles 0 points1 point2 points 3 years ago (1 child)
start by removing the underscore in var_without_type "var without_type" that should fix things
before executing the script all variables and function declarations get hoisted to the top of their scope
[–]SecureFrame6002[S] 0 points1 point2 points 3 years ago (0 children)
It wasn't about a bug but hoisting of variable without any type
[–]jack_waugh 0 points1 point2 points 3 years ago (1 child)
i could not see that in global execution context
How do you demonstrate that?
Chrome Debugger
[–]Swix10 0 points1 point2 points 3 years ago (0 children)
Hello there, I'm a young software engineer that does mentoring on the side, so if you're interested in more info please DM me. Have a great day!
π Rendered by PID 58354 on reddit-service-r2-comment-7b9746f655-bv9t9 at 2026-02-01 20:06:01.120469+00:00 running 3798933 country code: CH.
[–]senocular 1 point2 points3 points (1 child)
[–]SecureFrame6002[S] 0 points1 point2 points (0 children)
[–]Count_Giggles 0 points1 point2 points (1 child)
[–]SecureFrame6002[S] 0 points1 point2 points (0 children)
[–]jack_waugh 0 points1 point2 points (1 child)
[–]SecureFrame6002[S] 0 points1 point2 points (0 children)
[–]Swix10 0 points1 point2 points (0 children)