Hello World!
I felt bored after completing the Ultimate Cheat Sheet Compilation, so I just decided to create another one! The most complete javascript cheat sheet and resource compilation you can find online!
π - Waaait, don't leave this page without bookmarking it!!
Read also:
400+ JavaScript Interview Questions π With Answers π
Lorenzo for World In Dev γ» Apr 27 '21
β‘ Giveaway β‘
We are giving away any course you need on Udemy. Any price any course.
Steps to enter the giveaway
--> React to this post
--> Subscribe to our Newsletter <-- Very important
PS: It took me around 10 hours to complete the article - So please remember the like β€οΈ and super like π¦
Table of content
JavaScript is a scripting or programming language that allows you to implement complex features on web pages β every time a web page does more than just sit there and display static information for you to look at β displaying timely content updates, interactive maps, animated 2D/3D graphics, scrolling video jukeboxes, etc. β you can bet that JavaScript is probably involved. It is the third layer of the layer cake of standard web technologies. MDN To put things simply, JavaScript is an object orient programming language designed to make web development easier and more attractive. In most cases, JavaScript is used to create responsive, interactive elements for web pages, enhancing the user experience. Things like menus, animations, video players, interactive maps, and even simple in-browser games can be created quickly and easily with JavaScript. JavaScript is one of the most popular programming languages in the world. BitDegree - What Is JavaScript Used For And Why You Should Learn It Mozillaβs JavaScript Guide Scope. If you don't understand this intimately then you aren't that serious about this language. This is the number one point intentionally and I cannot stress it enough. Architecture. You don't have to be a master software architect, but if you cannot perform some basic planning and put pieces together without massive layers of tooling you are an imposter. Expecting frameworks and other tools to simply do it for you isn't very impressive. DOM. It is very common to see developers hiding from the DOM by layers of abstractions and other stupid crap. querySelectors are great, but are also 2800x slower than the standard DOM methods. That isn't trivial. These methods are super simple, so there is no valid excuse for developers fumbling over this or hiding in fear. http://prettydiff.com/guide/unrelated_dom.xhtml Node.js If you are a serious developer should have a pretty solid grasp of how to walk the file system. You should understand how to conveniently read files as text or less conveniently read files as bit for bit binary buffers. Timing and asynchronous operations. Events, timers, network requests are all asynchronous and separate from each other and exist both in Node and in the browser. You have to be able to understand how to work with callbacks or promises. Accessibility. The interactions imposed by JavaScript can present accessibility barriers. A serious JavaScript developer is already familiar with WCAG 2.0 and knows how to work within its recommendations or when to push back on violating business requirements. Security. You need to have at least a basic understanding of security violations, security controls, and privacy. You don't need to be a CISSP, but you need to be able to supply recommendations and avoid obvious failures. If you cannot get this right in the most basic sense you aren't a serious developer. Data structures. You need to understand how to organize data in a way that allows the fastest possible execution without compromising maintenance. This is something that is learned through academic study and repeated experience writing applications. Presentation and semantics. You really need to have a basic understanding how to properly organize the content your users will consume and how to present in a consumable way efficiently. This is something almost completely learned from experience only. You might think CSS and HTML are simple skills that can be picked up when needed, but you would be absolutely wrong. Knowing when to avoid the bullshit. Many developers lack the years of experience to be confident in their performance.... so some of these developers will try to fake it. Don't be an imposter, because everybody will see straight through it. Hoping mountains of abstractions, tooling, frameworks, compilers, and other bullshit will save you just bogs down your application and screws over your teammates. If you aren't confident then be honest about that and seek mentorship or get involved with open source software outside of work.For beginners
What is JS (Javascript)
What it used for?
Hello World In Javascript:
alert("Hello World") β Output data in an alert box in the browser window
confirm("Hello World") β Opens up a yes/no dialog and returns true/false depending on user click
console.log("Hello World") β Writes information to the browser console, good for debugging purposes
document.write("Hello World") β Write directly to the HTML document
prompt("Remember the like!") β Creates a dialogue for user input
Resources to learn it:
JavaScript track on Codecademy: Interactive tutorials for beginners.
JavaScript for Cats by Max Ogden
Eloquent JavaScript by Marijn Haverbeke
Wikibooksβ JavaScript book
JavaScript Lectures by Douglas Crockford
You Don't Know JS - Possibly the best book written on modern JavaScript, completely readable online for free, or can be bought to support the author.
braziljs/js-the-right-way - An easy-to-read, quick reference for JS best practices, accepted coding standards, and links around the Web.
JSbooks - Directory of free JavaScript ebooks.
Superhero.js - A collection of resources about creating, testing and maintaining a large JavaScript code base.
SJSJ - Simplified JavaScript Jargon is a community-driven attempt at explaining the loads of buzzwords making the current JavaScript ecosystem in a few simple words.
How to Write an Open Source JavaScript Library - A comprehensive guide through a set of steps to publish a JavaScript open source library.
JavaScript Tutorials - Learn Javascript online from a diverse range of user ranked online tutorials.
Functional-Light JavaScript - Pragmatic, balanced FP in JavaScript.
Clean Code JavaScript - Clean Code concepts adapted for JavaScript.
List at GitHub - Awesome Javascript - By Alexandru Gherasim
At Reddit - What 10 Things Should a Serious Javascript Developer Know Right Now?
JS Cheat Sheet:
--> Download the PDF Version of this Cheat Sheet here
Include Javascript:
<script type="text/javascript"></script>
// or Include it in an external file (this is a comment)
/* This is also another way you can insert comments,
Multiline normally */
<script src="myscript.js"></script><code></code>
// PS: Remember to sub to our newsletter for the Giveaway!
Variables:
var myVariable = 22; //this can be a string or number. var is globally defined
let myVariable = 22; //this can be a string or number. let can be reassigned
const myVariable = 22; //this can be a string or number. can't be reassigned
JavaScript Variables - w3schools
Article No Longer Available
Data Types:
//string
let string = 'ASCII text';
//int
let integer = 123456789;
//float
let float = 123.456;
//boolean, can be true or false
let t = true;
let f = false;
//undefined
let undef;//defaults to undefined
let undef = undefined;//not common, use null
//null
let nul = null;
//array
let arr = ['Hello','my','name','is','Dr.Hippo',123,null];
//object
let person = {'name':'John Smith','age':27};
//function
let fun = function(){
return 42;
}
Source - Datatypes In JavaScript - c-sharpcorner.com
Operators
Basic Operators
+ β Addition
- β Subtraction
* β Multiplication
/ β Division
(...) β Grouping operator, operations within brackets are executed earlier than those outside
% β Modulus (remainder )
++ β Increment numbers
-- β Decrement numbers
Article No Longer Available
Comparison Operators
== Equal to
=== Equal value and equal type
!= Not equal
!== Not equal value or not equal type
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to
? Ternary operator
Logical Operators
&& Logical and
|| Logical or
! Logical not
Bitwise Operators
& AND statement
| OR statement
~ NOT
^ XOR
<< Left shift
>> Right shift
>>> Zero fill right shift
Loops
for - loops through a block of code a number of times.
for (statement 1; statement 2; statement 3) {
// Coooode
}
for/in - loops through the properties of an object.
for/of - loops through the values of an iterable object.
while - loops through a block of code while a specified condition is true.
let i=0;
while (i < 10) {
console.log(i);
i++;
}
Break and Continue
When you use break without a label, it terminates the innermost enclosing while, do-while, for, or switch immediately and transfers control to the following statement.
When you use break with a label, it terminates the specified labeled statement.When you use continue without a label, it terminates the current iteration of the innermost enclosing while, do-while, or for statement and continues execution of the loop with the next iteration. In contrast to the break statement, continue does not terminate the execution of the loop entirely. In a while loop, it jumps back to the condition. In a for loop, it jumps to the increment-expression.
When you use continue with a label, it applies to the looping statement identified with that label.
Source - Loops and iteration - MDN
Article No Longer Available
Strings
dev.to Article - 10 JavaScript string methods you should know - by @frugencefidel
Escape characters
\' β Single quote
\" β Double quote
\\ β Backslash
\b β Backspace
\f β Form feed
\n β New line
\r β Carriage return
\t β Horizontal tabulator
\v β Vertical tabulator
Array and array methods
Top 10 JavaScript Array Methods You Should Know - By Rachel Cole at morioh.com
concat(arr1,[...]) // Joins two or more arrays, and returns a copy of the joined arrays
copyWithin(target,[start],[end]) // Copies array elements within the array, to and from specified positions
entries() // Returns a key/value pair Array Iteration Object
every(function(currentval,[index],[arr]),[thisVal]) // Checks if every element in an array pass a test
fill(val,[start],[end]) // Fill the elements in an array with a static value
filter(function(currentval,[index],[arr]),[thisVal]) // Creates a new array with every element in an array that pass a test
find(function(currentval,[index],[arr]),[thisVal]) // Returns the value of the first element in an array that pass a test
findIndex(function(currentval,[index],[arr]),[thisVal]) // Returns the index of the first element in an array that pass a test
forEach(function(currentval,[index],[arr]),[thisVal]) // Calls a function for each array element
from(obj,[mapFunc],[thisVal]) // Creates an array from an object
includes(element,[start]) // Check if an array contains the specified element
indexOf(element,[start]) // Search the array for an element and returns its position
isArray(obj) // Checks whether an object is an array
join([seperator]) // Joins all elements of an array into a string
keys() // Returns a Array Iteration Object, containing the keys of the original array
lastIndexOf(element,[start]) // Search the array for an element, starting at the end, and returns its position
map(function(currentval,[index],[arr]),[thisVal]) // Creates a new array with the result of calling a function for each array element
pop() // Removes the last element of an array, and returns that element
push(item1,[...]) // Adds new elements to the end of an array, and returns the new length
reduce(function(total,currentval,[index],[arr]),[initVal]) // Reduce the values of an array to a single value (going left-to-right)
reduceRight(function(total,currentval,[index],[arr]),[initVal]) // Reduce the values of an array to a single value (going right-to-left)
reverse() // Reverses the order of the elements in an array
shift() // Removes the first element of an array, and returns that element
slice([start],[end]) // Selects a part of an array, and returns the new array
some(function(currentval,[index],[arr]),[thisVal]) // Checks if any of the elements in an array pass a test
sort([compareFunc]) // Sorts the elements of an array
splice(index,[quantity],[item1,...]) // Adds/Removes elements from an array
toString() // Converts an array to a string, and returns the result
unshift(item1,...) // Adds new elements to the beginning of an array, and returns the new length
valueOf() // Returns the primitive value of an array
Functions
Syntax
function name(parameter1, parameter2, parameter3) {
// code to be executed
}
Examples
function myFunction(p1, p2) {
return p1 * p2; // The function returns the product of p1 and p2
}
let x = myFunction(4, 3); // Function is called, return value will end up in x
function myFunction(a, b) {
return a * b; // Function returns the product of a and b
}
// Convert Fahrenheit to Celsius:
function toCelsius(fahrenheit) {
return (5/9) * (fahrenheit-32);
}
document.getElementById("demo").innerHTML = toCelsius(77);
Source - JavaScript Functions - w3schools
Maths
Finally - How to understand math - Awesome resource list π
Lorenzo for World In Dev γ» Mar 30 '21
Properties
E β Eulerβs number
LN2 β The natural logarithm of 2
LN10 β Natural logarithm of 10
LOG2E β Base 2 logarithm of E
LOG10E β Base 10 logarithm of E
PI β The number PI
SQRT1_2 β Square root of 1/2
SQRT2 β The square root of 2
Date
Article No Longer Available
Javascript date objects allow us to work with date and time. We can retrieve information for it by creating a date and assign and assigning it to a variable:
let d = new Date(); // We usually call it d or date
Date object provide us a lot of different methods, the most used are year, month, day, hours, minutes, seconds, and milliseconds. Remember that you always have to precise the entire year (1950 and not only 50), that we always start with 0 (so, for example, December is the eleventh, a minute is composed of 59 seconds...) and that day is in a 24 hours format.
You can then retrieve from date a lot of differents info:
d.getDate() Returns the day of the month (from 1-31)
d.getDay() Returns the day of the week (from 0-6)
d.getFullYear() Returns the year
d.getHours() Returns the hour (from 0-23)
d.getMilliseconds() Returns the milliseconds (from 0-999)
d.getMinutes() Returns the minutes (from 0-59)
d.getMonth() Returns the month (from 0-11)
d.getSeconds() Returns the seconds (from 0-59)
We can also set things... Open the article to continue reading
Events
Mouse
onclick - The event occurs when the user clicks on an element
oncontextmenu - User right-clicks on an element to open a context menu
ondblclick - The user double-clicks on an element
onmousedown - User presses a mouse button over an element
onmouseenter - The pointer moves onto an element
onmouseleave - Pointer moves out of an element
onmousemove - The pointer is moving while it is over an element
onmouseover - When the pointer is moved onto an element or one of its children
onmouseout - User moves the mouse pointer out of an element or one of its children
onmouseup - The user releases a mouse button while over an element
Keyboard
onkeydown - When the user is pressing a key down
onkeypress - The moment the user starts pressing a key
onkeyup - The user releases a key
Frame
onabort - The loading of a media is aborted
onbeforeunload - Event occurs before the document is about to be unloaded
onerror - An error occurs while loading an external file
onhashchange - There have been changes to the anchor part of a URL
onload - When an object has loaded
onpagehide - The user navigates away from a webpage
onpageshow - When the user navigates to a webpage
onresize - The document view is resized
onscroll - An elementβs scrollbar is being scrolled
onunload - Event occurs when a page has unloaded
Form
onblur - When an element loses focus
onchange - The content of a form element changes (for , and )
onfocus - An element gets focus
onfocusin - When an element is about to get focus
onfocusout - The element is about to lose focus
oninput - User input on an element
oninvalid - An element is invalid
onreset - A form is reset
onsearch - The user writes something in a search field (for )
onselect - The user selects some text (for and )
onsubmit - A form is submitted
Drag
ondrag - An element is dragged
ondragend - The user has finished dragging the element
ondragenter - The dragged element enters a drop target
ondragleave - A dragged element leaves the drop target
ondragover - The dragged element is on top of the drop target
ondragstart - User starts to drag an element
ondrop - Dragged element is dropped on the drop target
Clipboard
oncopy - User copies the content of an element
oncut - The user cuts an elementβs content
onpaste - A user pastes content in an element
Media
onabort - Media loading is aborted
oncanplay - The browser can start playing media (e.g. a file has buffered enough)
oncanplaythrough - When browser can play through media without stopping
ondurationchange - The duration of the media changes
onended - The media has reached its end
onerror - Happens when an error occurs while loading an external file
onloadeddata - Media data is loaded
onloadedmetadata - Meta Metadata (like dimensions and duration) are loaded
onloadstart - Browser starts looking for specified media
onpause - Media is paused either by the user or automatically
onplay - The media has been started or is no longer paused
onplaying - Media is playing after having been paused or stopped for buffering
onprogress - Browser is in the process of downloading the media
onratechange - The playing speed of the media changes
onseeked - User is finished moving/skipping to a new position in the media
onseeking - The user starts moving/skipping
installed - The browser is trying to load the media but it is not available
onsuspend - Browser is intentionally not loading media
ontimeupdate - The playing position has changed (e.g. because of fast forward)
onvolumechange - Media volume has changed (including mute)
onwaiting - Media paused but expected to resume (for example, buffering)
animationend - A CSS animation is complete
animationiteration - CSS animation is repeated
animationstart - CSS animation has started
Other
transitionend - Fired when a CSS transition has completed
onmessage - A message is received through the event source
onoffline - Browser starts to work offline
ononline - The browser starts to work online
onpopstate - When the windowβs history changes
onshow - A element is shown as a context menu
onstorage - A Web Storage area is updated
ontoggle - The user opens or closes the element
onwheel - Mouse wheel rolls up or down over an element
ontouchcancel - Screen touch is interrupted
ontouchend - User finger is removed from a touch screen
ontouchmove - A finger is dragged across the screen
ontouchstart - Finger is placed on touch screen
Asynchronous JS and Error handling
Article No Longer Available
SetTimeout will wait foo seconds and then execute the action. SetInterval will execute this same action every foo seconds.
Both can be inline or multiline, I recommend using multiline 99% of the time. It's important to notice that they work in milliseconds.
SetTimeout:
setTimeout(function(){
alert("Hello World!");
}, 2000); // 2 seconds
setTimeout(function(){ alert("The fifth episode of the series"); }, 3000);
SetInterval:
setInterval(function() {
alert("I want to show you another Javascript trick:");
}, 1000);
setInterval(function() {alert("How to work with SetTimeout and SetInterval");}, 1000);
- If you want to remove the first delay you have to add code a first time out of the function. I recommend you save this code in a separate function you can call whenever you need. Continue reading here
Article No Longer Available
First, it's important to notice that a majority of backend actions have an unknown result, we don't know if it will work when we write our code. So we always have to write two different codes, one if the action works, another if the action results in an error. This is exactly how a try/catch work, we submit a code to try, if it works code continues, if it doesn't we catch the error (avoiding the app crashing) and run another code. This is a very common thing we don't only use in web development (also in Android app development with java for example).
Try / Catch
try {
// Try to run this code
// For example make a request to the server
}
catch(e) {
console.log(e)
// if any error, Code throws the error
// For example display an error message to the user
}
Promises
The big problem with try/catch is that when you have to nest it (and you will have), it's really messy and difficult to read and write. So Javascript support promises with async functions:
Syntax: new Promise (executor)
executor= (accept, reject) =>{}
var asyncronus_function = (number)=>
{
return new Promise( (accept, reject)=>
{
})
}
This function returns a promise object.
If function end well we return a accept(), otherwise reject()
More here
Projects ideas to become a javascript master
Projects ideas to become a javascript master π Resource compilation π₯ + Giveawayβ‘
Lorenzo for World In Dev γ» Apr 10 '21
a) General (for beginners)
- Converters
- Word Counter
- Timer / Clock
- Random password generator
- Calculator
b) Games
- Guess the number
- Math time!
- Other Games
- Log-in, Sign-up
- Filter
- To-Do List
- Social
- Portfolio
Open the post for more info about each project!
Other resources:
Complete JS cheat sheets:
Incredible resource --> By website setup
Two Others:
By overapi
By HTML cheat sheet.com - Interactive
JS promises (Asynchronous JS):
Article No Longer Available
Article No Longer Available
JS Arrays:
JS Loops:
JS preprocessor:
CoffeeScript:
Others:
At karloeaspirity.io
Quick reference - By autotelicum - PDF Version
EJS:
Babel:
JavaScript-based Frameworks & Libraries:
Article Angular vs vue vs react at codeinwp.com
Best Javascript Frameworks - article at hackr.io
Angular
Vue
React
Others:
By react cheat sheet.com
At GitHub: React + Typescript cheat sheet
JQuery
AJAX intro + cheat sheet at GitHub
By ascarotero.com - Really well done
By Website Setup - PDF Version
Article about top 10 jquery cheat sheets
Others
Ember.js:
Meteor:
Mithril:
Node
Other Resources:
Advanced Topics
- How Browsers Work: Behind the scenes of modern web browsers
- Learning Advanced JavaScript by John Resig
- JavaScript Advanced Tutorial by HTML Dog
- WebGL Fundamentals
- Learning JavaScript Design Patterns by Addy Osmani
- Intro to Computer Science in JavaScript
- Immutable data structures for JavaScript
Libraries/Frameworks/Tools
- Introduction to React video
- React Interview Questions
- JavaScript Promises: A Tutorial with Examples
- Khan Academy: Making webpages interactive with jQuery
- A Beginnerβs Guide To Grunt: Build Tool for JavaScript
- Getting Started with Underscore.js
- jQuery Course by Code School
- Thinkster.io Courses on React and Angular
- The Languages And Frameworks You Should Learn In 2016
- ES6 Tools List on GitHub
- Getting Started with Redux
Server-side JavaScript
- Real-time Web with Node.js Course by Code School
- NodeSchool Course
- Node.js First Look on Lynda
- All about NodeJS Course on Udemy
- Server-side Development with NodeJS Course on Coursera
Read also:
Projects ideas to become a javascript master π Resource compilation π₯ + Giveawayβ‘
Lorenzo for World In Dev γ» Apr 10 '21
Finally - How to understand math - Awesome resource list π
Lorenzo for World In Dev γ» Mar 30 '21
25 Udemy Courses Worth Your Money & Time π
Garvit Motwani for World In Dev γ» Apr 22 '21
Thanks for reading and Happy coding β€
Full Compilation of cheat sheets:
Article No Longer Available
β‘Giveaway β‘
We are giving away any course you need on Udemy. Any price any course.
Steps to enter the giveaway
--> React to this post
--> Subscribe to our Newsletter <-- Very important
--> Follow me on Twitter <-- x2 Chances of winning
The winner will be announced on May 1, Via Twitter
Subscribe to my Newsletter!
- The PDF version of this article!!!
- Monday: Weekly digeeeeeests!!!
- Wednesday: Discussions and dev insights - We debate around developer lifes - Examples: The importance of coffee behind development / If you weren't a dev, you'd be a...β
- Gifts, lots of π. We send cheat sheets, coding advice, productivity tips, and many more!
- That's --> free <-- and you help me!
PS: It took me around 10 hours to complete the article - So please remember the like β€οΈ and super like π¦ - Let's reach the top of the month this time π
Top comments (22)
Wow, this is amazing. I really appreciate the amount of work and time you put into these articles. And btw, I liked and super liked this post not only for the giveaway but also because you deserve it !
β€οΈπβ€οΈ
This comment really improved my today motivation, that's why I dedicate all this work and time to my articles, thank to you, the community.
Expect many more such things, especially from our newsletter. You will be in the "what people say about me / feedback" section for sure!
Also, if you have something you'd like to see, don't hesitate to write me here at DEV.
I see youβre using
var
throughout the code blocks of your article. Thatβs really bad practice, so please replace them withconst
, orlet
if necessary, so new devs seeing this article donβt use it.Sure, I change the content right now, thank you for your advice.
Let me know if you have any other things you think I can improve / change π
Just a tip:
When making code blocks, for syntax highlighting, add the language you're code is next to the 3 ticks
example:
(Without the spaces)
Thank you very much, in fact, I don't know why I didn't know that before, I don't think there is anything about that in the DEV markdown documentation. I will for sure use this trick in my next writings.
No worries :)
Markdown is the same everywhere. You can do the same thing in GitHub too
Woah, this article is fantastic - especially for a 13-year-old beginner like me. I've scoured the internet for SO LONG trying to find this, and you've delivered it - finally!
The only negative thing about this article is that English can be improved, but otherwise, great job.
You have earned yourself a follow, like, and super like (because obviously).
β€οΈ
I can't say how much I appreciate this message, it makes me really want to continue!
I'm sorry for my English level, I'm not my mother tongue but try to improve every day.
Also, if you're interested in other resources like that or in the pdf version of this article, I just launched my newsletter! worldindev.ck.page π
Yeah, I signed up when I read this article!
This is useless. What one really needs is 1 resource, not 200, 500, 1000 etc. Noone ever does anything with those lists except putting them in the bookmarks folder to "check some time later" which never comes.
Ok, what would you prefer to see? If you have an article to propose to me, I would be very interested. I am here to learn.
I think, and given the other feedbacks that may be true, that Cheat sheets are very useful. Personally, I use them a lot when learning a new programming language. Then the other resources are a plus that you are free to ignore if you want.
Seeing your latest comments, others have been reported as low quality / non-constructive. Maybe try doing constructive remarks, saying what we can improve.
Thank. Let me know if I can do something for you.
Excellent, thank you so much.
Very impressive post. Can't wait to see what future tips you have to share! Excellent!
worldindev.ck.page π
Thanks for this π₯
β€οΈ
Got a lot of Resourse Information at one place.Thanks For sharing .
Thanks for the article, thanks for your time!!! :-)
And thank you for your comment!
if you'd like to receive other articles like this / download the pdf version of this one, I just launched my newsletter! worldindev.ck.page/ π
Brilliant! Thanks a million for your work.
what is that code></code on the first include block?
Guess it is an edit issue from dev.to?