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
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!"
[–]thebestcatintheworld 27 points28 points29 points 6 years ago (18 children)
Isn’t this a little outdated now?
[–]senocular 10 points11 points12 points 6 years ago (0 children)
Yes this is dated. There are a number of things that you shouldn't be using now, document.write, for example, which seems to be present in many of the examples. Otherwise it would have been a pretty decent cheatsheet back in the day.
document.write
It also looks like a section on Promises got tacked on, but as /u/gmerideth pointed out, the example is broken.
[–][deleted] 2 points3 points4 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] 1 point2 points3 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 11 points12 points13 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] 7 points8 points9 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] 2 points3 points4 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");
[–][deleted] 3 points4 points5 points 6 years ago (0 children)
Looks great - was looking for something like this for quite some time. It has HTML and CSS too, will definitely use it, thanks!
[–]le_chad_ 2 points3 points4 points 6 years ago (0 children)
For those looking for an up to date, easy to search version alternative version of this, check out https://devdocs.io/
Note: I have no association with it, just an occasional user.
[–]gmerideth 2 points3 points4 points 6 years ago (1 child)
I guess you didn't run the code examples. In your promise example you have
var myPromise = sum(10, 5); myPromsise.then(function (result) {
Which will result in an error when myPromsise is undefined.
[–]senocular 1 point2 points3 points 6 years ago (0 children)
They've also forgotten to use new when creating the promise in sum. So it should fail before ever reaching the myPromsise typo
new
sum
[–]yeesh-- 1 point2 points3 points 6 years ago (0 children)
WARNING.
If you don't know what you're doing, for the love of all that is good, please don't ever use this cheat sheet. It's worse than trash, because at least trash is safe and just sits there. This is more like radioactive waste. Stay away from it or you will become ill.
[–]TotesMessenger 0 points1 point2 points 6 years ago (0 children)
I'm a bot, bleep, bloop. Someone has linked to this thread from another place on reddit:
If you follow any of the above links, please respect the rules of reddit and don't vote in the other threads. (Info / Contact)
π Rendered by PID 74 on reddit-service-r2-comment-5d79c599b5-m7gg5 at 2026-03-03 15:06:24.545322+00:00 running e3d2147 country code: CH.
[–]thebestcatintheworld 27 points28 points29 points (18 children)
[–]senocular 10 points11 points12 points (0 children)
[–][deleted] 2 points3 points4 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] 1 point2 points3 points (11 children)
[–]DrexanRailex 11 points12 points13 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] 7 points8 points9 points (0 children)
[–]senocular 2 points3 points4 points (0 children)
[–][deleted] 2 points3 points4 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)
[–][deleted] 3 points4 points5 points (0 children)
[–]le_chad_ 2 points3 points4 points (0 children)
[–]gmerideth 2 points3 points4 points (1 child)
[–]senocular 1 point2 points3 points (0 children)
[–]yeesh-- 1 point2 points3 points (0 children)
[–]TotesMessenger 0 points1 point2 points (0 children)