Show Menu

JavaScript Cheat Sheet (DRAFT) by

Developer’s essential

This is a draft cheat sheet. It is a work in progress and is not finished yet.

JavaScript Basics

Including JavaScript in an HTML Page
<script type="text/javascript">
    //JS code goes here
Call an External JavaScript File
<script src="my­scr­ipt.js­"­></­scr­ipt­><c­ode­></­cod­e>
Including Comments
// comment here : Single line comments
/* comment here */ : Multi-line comments

Variables in JavaScript

var, const, let :
var : The most common variable. Can be reassigned but only accessed within a function. Variables defined with var move to the top when code is executed.
const : Can not be reassigned and not accessible before they appear within the code.
let : Similar to const, however, let variable can be reassigned but not re-dec­lared
Data Types :
var age = 23 : Numbers
var x : Variables
var a = "­ini­t" : Text (strings)
var b = 1 + 2 + 3 : Operations
var c = true : True or fase statements
const PI = 3.14 : Constant numbers
Objects :
// Example 1
var name = {first­Nam­e:"J­ohn­", lastNa­me:­”Do­e"}
// Example 2
var person = {