Title: JavaScript function expression vs function statement (Example)
Open Graph Title: JavaScript function expression vs function statement (Example)
X Title: JavaScript function expression vs function statement (Example)
Description: A protip by steveniseki about javascript.
Open Graph Description: A protip by steveniseki about javascript.
X Description: A protip by steveniseki about javascript.
Keywords:
Mail addresses
support@coderwall.com
Opengraph URL: https://www.coderwall.com/p/f4t65q/javascript-function-expression-vs-function-statement
X: @coderwall
Domain: coderwall.com
IPv4 address: 66.71.205.0
{
"@context": "http://schema.org",
"@type": "Article",
"@id": "javascript-function-expression-vs-function-statement",
"author": {
"@type": "Person",
"name": "Steven Iseki"
},
"dateModified": "2019-09-09 08:39:49 UTC",
"datePublished": "2019-09-09 08:39:49 UTC",
"headline": "JavaScript function expression vs function statement (Example)",
"url": "/p/f4t65q/javascript-function-expression-vs-function-statement",
"commentCount": 1,
"keywords": "javascript",
"articleBody": "function expressions and function statements are very similar in JavaScript, the difference is how the browser loads them into the execution context.\r\n\r\n // function statement\r\n function foo() {\r\n }\r\n \r\n // function expression\r\n var foo = function() {\r\n };\r\n \r\n\u003cb\u003efunction statements\u003c/b\u003e\r\n \r\nA function statement loads before any code is executed. This behavior of function statements is called hoisting, which allows a function to be used before it is defined.\r\n\r\n alert(foo()); // Alerts \"hello from foo\".\r\n function foo() { return \"hello from foo\"; } \r\n\r\n\r\n\u003cb\u003efunction expressions\u003c/b\u003e \r\n \r\nA function expression associates a value with a variable, just like any other assignment statement. function expressions load only when the interpreter reaches the definition of the function.\r\n\r\n alert(foo()); // ERROR!\r\n var foo = function() { return \"hello from foo\"; } \r\n \r\n[more info on JavaScript concepts](http://bolinfest.com/javascript/misunderstood.html)",
"description": "A protip by steveniseki about javascript.",
"publisher": {
"@type": "Organization",
"name": "Coderwall",
"logo": {
"@type": "ImageObject",
"url": "/logo.png"
},
"url": "https://www.coderwall.com/"
},
"image": "/logo.png"
}
{
"@context": "http://schema.org",
"@type": "Comment",
"datePublished": "2014-04-29 05:27:20 UTC",
"text": "Such a subtle code but huge difference between how they behave. :)",
"upvoteCount": 2,
"author": {
"@type": "Person",
"name": "Veera"
},
"about": {
"@type": "Article",
"@id": "javascript-function-expression-vs-function-statement"
}
}
| og:site_name | Coderwall |
| og:type | website |
| og:image | https://coderwall-assets-0.s3.amazonaws.com/uploads/user/avatar/98069/stevenm.jpg |
| twitter:url | https://www.coderwall.com/p/f4t65q/javascript-function-expression-vs-function-statement |
| twitter:site_name | Coderwall |
| twitter:card | summary |
| twitter:creator:id | 407006088 |
| twitter:image | https://coderwall-assets-0.s3.amazonaws.com/uploads/user/avatar/98069/stevenm.jpg |
| author | https://www.coderwall.com/steveniseki |
| csrf-param | authenticity_token |
| csrf-token | yv28BjT1kZyFEFa6-ScF1GfQfq5L99BTisC0jG2aUnWcY2cdiQ6CnUWqO4S6eeKvbGL3ATbN02xhoCnD58DvOg |
Links:
| Server | envoy |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
| Last-Modified | Mon, 09 Sep 2019 08:39:49 GMT |
Viewport: width=device-width,initial-scale=1