Skip to content

Commit

Permalink
Adding a Question between 17 and 18 (ganqqwerty#74)
Browse files Browse the repository at this point in the history
Adding a Question between 17 and 18
  • Loading branch information
ganqqwerty authored Jun 2, 2019
2 parents 48f1f7e + b461d61 commit b9cc289
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ var foo = function bar() {
// bar is undefined here
```

## Question 17. What is the difference between declaring a function in the formats listed below?
## Question 17a. What is the difference between declaring a function in the formats listed below?

```javascript
var foo = function() {
Expand Down Expand Up @@ -510,6 +510,21 @@ function bar() {
console.log("Hi I am inside Foo");
}
```
## Question 17b. What is the output of the following?

```javascript
bar();
(function abc(){console.log('something')})();
function bar(){console.log('bar got called')};
```
### Answer

The output will be :
```
bar got called
something
```
Since the function is called first and defined during parse time the JS engine will try to find any possible parse time definitions and start the execution loop which will mean function is called first even if the definition is post another function.

## Question 18. In which case the function definition is not hoisted in JavaScript?

Expand Down

0 comments on commit b9cc289

Please sign in to comment.