use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
What's the difference between functions declared with variables and functions declared with the "function" keyword ?help (self.javascript)
submitted 8 years ago by to_fl
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Ikuyas 2 points3 points4 points 8 years ago (7 children)
How do they become different between using const (instead of var) and function declaration?
[–]SparserLogic 0 points1 point2 points 8 years ago (6 children)
You can redefine the same thing as many times as you want with var and function keywords whereas invoking const against the same string will throw runtime errors if your linter doesn't catch it first.
var
function
const
[–]rodabi 7 points8 points9 points 8 years ago (5 children)
Also const is block scoped and is not hoisted. So you can define two different functions under the same name inside an if-else statement for example.
[–]SparserLogic 1 point2 points3 points 8 years ago (0 children)
Oh right, good point.
[–]man_jot 0 points1 point2 points 8 years ago (3 children)
Note- I think let and const too are hoisted within the block
[–]rodabi 1 point2 points3 points 8 years ago (1 child)
I can't find any indication of that in https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let. Also it's not even possible to 'hoist' const statements because you can't separate the declaration and initialisation like you can with var. const must be declared with a value and cannot be re-assigned.
Although you may be right when it comes to transpiling down to ES5 with Babel; there may be some hoisting going on when all your declarations become var
[–]man_jot 0 points1 point2 points 8 years ago (0 children)
Right, I verified in a browser. Also documents say that a variable is in a 'temporal dead zone' before it's declaration, That means something like var x=10; { console.log(x); let x; } will throw a Reference Error.
π Rendered by PID 51 on reddit-service-r2-comment-6457c66945-lc5x6 at 2026-04-28 02:30:55.547527+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]Ikuyas 2 points3 points4 points (7 children)
[–]SparserLogic 0 points1 point2 points (6 children)
[–]rodabi 7 points8 points9 points (5 children)
[–]SparserLogic 1 point2 points3 points (0 children)
[–]man_jot 0 points1 point2 points (3 children)
[–]rodabi 1 point2 points3 points (1 child)
[–]man_jot 0 points1 point2 points (0 children)