Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

@lke0
Copy link

@lke0 lke0 commented Feb 13, 2014

bar is undefined in current code (it uses function expression)

@timruffles
Copy link
Collaborator

Thanks - but that's intended. Read the next explanation block - it's
contrasting expressions to declarations.

On Thursday, 13 February 2014, Ling notifications@github.com wrote:

bar is undefined in current code (it uses function expression)

You can merge this Pull Request by running

git pull https://github.com/lke0/JavaScript-Garden master

Or view, comment on, or merge it at:

#210
Commit Summary

  • use function declaration according to the context

File Changes

Patch Links:

Reply to this email directly or view it on GitHubhttps://github.com//pull/210
.

@lke0
Copy link
Author

lke0 commented Feb 13, 2014

The above code gets transformed before execution starts.
I personally feel this explanation is confusing since var bar = function() {}; doesn't.

If it is intended to compare between two block, having two styles in the same block (function test(data) {) is confusing.

@timruffles
Copy link
Collaborator

It does actually - var bar gets hoisted so bar is initialised to undefined throughout its scope. The declaration gets hoisted and initialised as a function.

@timruffles timruffles closed this Feb 17, 2014
@lke0
Copy link
Author

lke0 commented Feb 17, 2014

Thanks for your reply!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.