Skip to content

Commit

Permalink
Clarify potential misunderstanding about hoisting
Browse files Browse the repository at this point in the history
  • Loading branch information
yangshun committed Apr 15, 2018
1 parent 4e11eeb commit bca9451
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion questions/javascript-questions.md
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,9 @@ However, do be aware of a potential XSS in the above approach as the contents ar

### Explain "hoisting".

Hoisting is a term used to explain the behavior of variable declarations in your code. Variables declared or initialized with the `var` keyword will have their declaration "hoisted" up to the top of the current scope. However, only the declaration is hoisted, the assignment (if there is one), will stay where it is. Let's explain with a few examples.
Hoisting is a term used to explain the behavior of variable declarations in your code. Variables declared or initialized with the `var` keyword will have their declaration "moved" up to the top of the current scope, which we refer to as hoisting. However, only the declaration is hoisted, the assignment (if there is one), will stay where it is.

Note that the declaration is not actually moved - the JavaScript engine parses the declarations during compilation and becomes aware of declarations and their scopes. It is just easier to understand this behavior by visualizing the declarations as being hoisted to the top of their scope. Let's explain with a few examples.

```js
// var declarations are hoisted.
Expand Down

0 comments on commit bca9451

Please sign in to comment.