SHORTEST JS Program 🔥window & this keyword | Namaste JavaScript Ep. 5

preview_player
Показать описание
Let's check out the Shortest Program in JavaScript and more about the window and this keyword. Understand how the Global Execution Context is created, global object, and this keyword is created in JS. We'll also talk about what happens under the hood of the JS Engine when you execute this shortest code in the browser.

JavaScript Engine creates a global object whenever you run any JS code. In the case of browsers, this global object is known as `window`, check out the video to see the demo of this global object created by the browser.

Topics Covered:
00:00 - Introduction to the Shortest JavaScript Program
00:19 - Behind the Scenes of the shortest JavaScript Program
00:39 - Global Execution Context and window object in JavaScript
01:40 - Introduction to this keyword in browser
04:38 - Code example of variables and functions in Global Memory Space
07:53 - Teaser - undefined vs. not defined in JS
08:03 - Thank you for watching Namaste JavaScript 🙏

Support this video series, NOT BY MONEY, but by sharing it with your friends. 🙏
I'll give my best to come up with great content and everything absolutely for free on YouTube. 😊

If you are active on Social Media,
please give a shoutout to Namaste JavaScript and help me reach more people. 🙏

Cheers,
Akshay Saini

Would love to Stay Connected with you ❤️

#NamasteJS #AkshaySaini
Рекомендации по теме
Комментарии
Автор

How was the video? Are you feeling excited? Please comment below. ❤️

akshaymarch
Автор

Your closing music to a video that talks about 'window' is 'Meri Samney wali khidki mein'? Legendary. 😆😆😆

nativeKar
Автор

for revision kids
Notes:
• window object is created by the JS engines of the respective browsers when global execution context is created.
• whenever an execution context is created a "this" variable is also created.
• at the global level "this" points to the global object( window object in case of browsers).
• anything that is not inside a function is the "global space".
• whenever we create any variables or functions in the "global space", they get attached to the global object( window object in case of browsers).

so to access the variables/function defined in the global space,
we can use any of the below:
console.log(window.a);
console.log(a);
console.log(this.a) //at the global space level, where this points to the window object

rhishishranjan
Автор

I m in tears of happiness. seriously never seen anyone who can teach programming language with such simplicity. thank you!!

pranatis
Автор

I swear to god your videos are more engaging than most of the web series on netflix.

rishavsharma
Автор

I don't think there's any other Youtuber teaching JS in such a depth and explaining everything so simply. Thank you Akshay sir!

JavaScript is really full of surprises.🤯

ankitsaxena
Автор

Summary

1. Shortest Program in JS: Empty file. Still, browsers make global EC and global space along with Window object.
2. Global Space: Anything that is not in a function, is in the global space.
3. Variables present in a global space can be accessed by a "window" object. (like window.a)
4. In global space, (this === window) object.

avikkundu
Автор

For revision:
1)Reserves the memory space specifically for GEC to be created in stack
2) GEC is created
3) Creates a 'Window': a javascript 'global object' which 'runs with GEC' with an object whose values are in global scope(can be accessed by using any of the key in 1:37 )
4) js object 'this' is created (really the name is 'this') and this level this=== window
5) then our script starts execution
The variable in javascript always assigns its value from Global level (unless specified earlier 'in the script' itself or in function)

and if you defined a variable (eg. a=10) : this.a===10; global.a===10;

Surely Akshay_sir:'Crystal Clear Javascript';

xFOXHOUND
Автор

That BIGG smile when you say " What is the Shortest Program in javascript " !!!.. 😂😂😂 Simply takes away our ❤❤❤

ankitapaul
Автор

Just a small point to make the meaning of 'this' more clear - When you have a global and local variable with same name 'x' and you want to refer to the global variable from the local context, you use 'this.x' or 'window.x'
Thanks for the awesome content Akshay...

girishthimmegowda
Автор

Thank you for this amazing video.

Summary:

The shortest code in JS is an empty JS file.
Even though the JS file is empty when you execute the code, a global execution context is created (you can see this in the call stack).

But along with the GEC, a global object is created which contains a lot of functions and methods, which can be used anywhere in the JS file.

In the case of a browser, which uses the V8 JS engine, this global object is called Window.

Global space: when you create a function or a variable, but the variable shouldn't be inside a function

At the global level, this points to the global object.
this === Window

var a=10;
console.log(a)/
console.log(window.a)/
console.log(this.a)

chandanmishra
Автор

I Love how sensei is so much passionate while teaching. It's like i am having fun. when someone teaches something with passion my focus rises to 100%

aayush
Автор

Hi Akshay, I wanted to learn JS from basics and depth. Tried learning from many other creators, But you are the stared @1am and whole playlist is addictive and am still here. May god bless you for sharing content for free.

phoenixop
Автор

The way he teaches, it seems like that he is the one who developed JavaScript as he explains each and every point in depth. He teaches so well and the way he dives deep into every concept of JavaScript is truly exceptional.

nehabisht
Автор

I have worked for over 3.5+ years, but I still don't know this. Great knowledgeable course.

HimanshuShekhar-be
Автор

I have never seen JavaScript explained in such a clear and easy manner
Thanks a lot Akshay Saini Sir!!!
Please keep making more such videos!!

shubhadabeldar
Автор

I like how he adds different music at the end of every video, amazing. window === "mere same wali Khadki mean" 👌😆

deepaksahu
Автор

Not even professor will able to teach like these. You are the Great Learner and so the Best Teacher. Thank You!

nikitashinde
Автор

Non stop 5th video of the series and I have paused just to appreciate how much effort you have given in helping us. Thanks a lot 🙏 ❤️

NiteshKumar-swuk
Автор

This playlist is very resourceful to learn and experiment some good concepts about Javascript.
Just discovered this from an idea that I got from this video.

```
var a = 10;
function x() {
var a = 11;
console.log(a); // Prints Local variable
console.log(window.a); // Prints Global variable
console.log(this.a); // Also prints Global variable
}
x();
```

Output:
11
10
10

:)

jigneshthakkar