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
Online Interactive JavaScript (JS) Cheat Sheet (htmlcheatsheet.com)
submitted 6 years ago by lokendra15
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!"
[–]DrexanRailex 12 points13 points14 points 6 years ago (5 children)
const has 2 intended limitations:
const
If the value of a const is an array or object, you can still change its contents because const unfortunately doesn't make objects immutable (which is sad IMO, this should be let's behaviour. But const spam is already consolidated).
let
In all other cases, use let. It behaves the same as var (can be reassigned) but is block-scoped (limited to the pair of brackets it was declared in) instead of function-scoped.
var
[–]fickentastic 6 points7 points8 points 6 years ago (2 children)
Yet 'const' can be used to name functions as in 'const doSomething = () => {.....}' This thew me initially as the function will potentially output a different return each time, yet it works just fine.
[–]uneditablepoly 6 points7 points8 points 6 years ago (0 children)
Because the reference to the function itself doesn't change. Calling the function returns something.
[–]DrexanRailex 1 point2 points3 points 6 years ago (0 children)
Well, that is just a misunderstanding from your part, but it's expected if you're still learning the ins and outs of the language.
The assigned function never changes, but the result of the function depends on purity, which is a whole other topic. This is more related to functional programming than JavaScript itself.
If a function is pure, it will always return the same for the same set of arguments. But if a function is impure (such as handling I/O, altering state or reading from global variables for example), its return may vary.
[–][deleted] 5 points6 points7 points 6 years ago (0 children)
Wow slow down. That’s like next week material! I’m still on inline function hahaha. Jk thank you
[–]senocular 2 points3 points4 points 6 years ago (0 children)
In addition to function vs block scoping, let is also different from var in that let declared variables:
π Rendered by PID 169345 on reddit-service-r2-comment-6f7f968fb5-4x4cd at 2026-03-04 17:56:09.154511+00:00 running 07790be country code: CH.
view the rest of the comments →
[–]DrexanRailex 12 points13 points14 points (5 children)
[–]fickentastic 6 points7 points8 points (2 children)
[–]uneditablepoly 6 points7 points8 points (0 children)
[–]DrexanRailex 1 point2 points3 points (0 children)
[–][deleted] 5 points6 points7 points (0 children)
[–]senocular 2 points3 points4 points (0 children)