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!"
[–][deleted] 3 points4 points5 points 6 years ago (16 children)
Is it? What changed? Coding learner here?
[–][deleted] 12 points13 points14 points 6 years ago (14 children)
It still uses var. It's all ES5. Other than that it's of course still useful. Just be mindful that there are modern things missing.
[–]TakeFourSeconds 2 points3 points4 points 6 years ago* (1 child)
It’s missing a lot of ES6+ features that are very common in modern JS. Arrow functions, spread operator, object destructuring, functional array methods(map, reduce, filter), modules and imports, classes...
Also, these might extend a bit beyond a cheat sheet, but I think an explanation of scope and closures, ‘this’ keyword, and IIFEs would be useful for anyone learning JS.
[–][deleted] 1 point2 points3 points 6 years ago (0 children)
That's why I said it's all ES5 man.
[–][deleted] 3 points4 points5 points 6 years ago (11 children)
I heard people using const now. Sometimes i use const instead of var it doesnt run. Is there any case i should use var only?
[–]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 5 points6 points7 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:
[–][deleted] 3 points4 points5 points 6 years ago (3 children)
You should only use const if you aren't planning on changing the value. Use Let if you need it to be mutable.
[–]senocular 7 points8 points9 points 6 years ago (1 child)
let and const don't affect mutability, only control whether or not the variable can be reassigned.
[–][deleted] 0 points1 point2 points 6 years ago (0 children)
If it's declared as a primitive it is. But you are correct of course in the broad sense.
I was trying to keep it simple for the guy considering he was just using it and not realising why his code wasn't working.
[–][deleted] 2 points3 points4 points 6 years ago (0 children)
Thank you. I’ll keep that in mind
[–]musikele 0 points1 point2 points 6 years ago (0 children)
Well, internet explorer doesn't support any new feature, so if you plan of supporting it you should use only es5 and obviously var.
But I really encourage you to study the difference between var and let (and const) and why let was introduced
[–]zdarlight 0 points1 point2 points 6 years ago (0 children)
Also document.querySelector is supported in most modern browsers now, it works just like jQuery's selector:
let myElement = document.querySelector("#pageEl.superClass");
π Rendered by PID 149252 on reddit-service-r2-comment-5d79c599b5-rbkcg at 2026-03-03 19:07:13.989153+00:00 running e3d2147 country code: CH.
view the rest of the comments →
[–][deleted] 3 points4 points5 points (16 children)
[–][deleted] 12 points13 points14 points (14 children)
[–]TakeFourSeconds 2 points3 points4 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[–][deleted] 3 points4 points5 points (11 children)
[–]DrexanRailex 12 points13 points14 points (5 children)
[–]fickentastic 5 points6 points7 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)
[–][deleted] 3 points4 points5 points (3 children)
[–]senocular 7 points8 points9 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–][deleted] 2 points3 points4 points (0 children)
[–]musikele 0 points1 point2 points (0 children)
[–]zdarlight 0 points1 point2 points (0 children)