You might be asked in the interview the question like this, what will be council locked here?
And as you can see here, we have console.log full and then full equals one.
And actually, this is a typical question regarding hoist him.
So what hoist an error means?
It means that the declaration of your variable will bubble to the top of the file.
And this is how it works in JavaScript when you're using a VAR keyword or function keyword.
So the question is what we will see here we have here counsel look for and foo is a variable, but as
you can see, it is not declared.
And then the second line we have foo equals one.
Actually, we will get here and there.
Let's check the sound and reloading the page and we're getting foo is not defined by it is happening
because, yes, the first line which is executed is console.log and food is not defined inside of a
file.
This is why we have this error.
So the correct answer here will get an error because Foo is not define it.
The main problem is here that typically you will get the answers just to answer on the paper without
any usage of computer, because obviously programmers are not using computers every day.
This is where you can't really tested in browser, and you need to understand how all this stuff is
working beforehand.
After a correct answer, you probably will ask something like this.
So the next question then will be OK, where console.log in here for?
But after this, we have our full equals tool.
And actually, here are the huge difference, because the first question we had here who equals one.
But we didn't have a creation of the variable.
But here we have our tool, which is actually a creation of the variable.
But you might think, OK, what happens after console.log, which means we will still get an error that
does not define it because of what happens later.
But actually, this is a wrong answer, because the main idea is that while declaration is bubbling
to the top of the file, which means it is exactly the same Cold Lake right in here WAFU.
And here were just a sign.
In footnote, all this is exactly the same code.
This is how JavaScript interprets this code.
This is why, if we will open the browser, you can see that we get an undefined it.
Why it is happening because actually, here we have our full.
And in this case, WAFU is undefined because we didn't assign any value.
After this, we have a console.log for where we get an undefined, and only after this were sign in
to inciteful, which means it won't be an error.
It won't be, too.
It will be undefined.
And this process is called hoisting.
If you answered correctly, you might get one more question regarding hoisting.
As you can see here, just question three we have here four equals three, then console.log four and
then VAR full.
And I think now you know the answer.
Yes, we have here were four and it bubbles to the top of the file, which means actually this who is
exactly like its in here, which means on the first line were defined in full property on the next line
were sign in foot or three.
And after this were console.log and full, which means it will be equal.
Three.
And it doesn't really matter that waffle is going at the end, it will be bubble to the top.
Let's check this out.
I'm reloading the page and we're getting three.
And this is exactly what we were waiting.
And you can get exactly the same question, but not with one, but with function keyword.
If you have somewhere in your called function and then the name of your function and then inside you,
right?
In some logic, the specific definition will bubble to the top, which actually means it doesn't really
matter in what line of your code you are right and function for.
It will be the first line that will be executed in JavaScript, which actually means if here before
I will call for, it is totally fine.
As you can see in browser, we're not getting any errors because this full function is bubble to the
top and it works exactly the same.
Like, Wow!
And here is one more important thing that you must add to your answer.
You must mention that we can use Konst and let.
And we don't have any problems with them because both const and let are not wobbling at all.
Which means if we're right here, const equals one, it won't bubble anywhere.
If it is defined on the 17th line, then it will be existed on the internet and flame, which means
we don't have any problems with constant LED.
And the way the JavaScript interprets our code is exactly the same code that we're seeing on the screen.
So you can just say that you're using const and let in every single project and you don't have any problem
was bubbling of the variable or was hoisting.