Javascript Cheat Sheet
The language of the web.
,Table of Contents
Javascript Basics 2
Variables 2
Arrays 3
Operators 4
Functions 5
Loops 7
If - Else Statements 7
Strings 7
Regular Expressions 9
Numbers and Math 10
Dealing with Dates 12
DOM Node 14
Working with the Browser 18
Events 21
Errors 27
WebsiteSetup.org - Beginner’s Javascript Cheat Sheet 1
, Javascript Basics
Including JavaScript in an HTML Page
<script type="text/javascript">
//JS code goes here
</script>
Call an External JavaScript File
<script src="myscript.js"></script><code></code>
Including Comments
//
Single line comments
/* comment here */
Multi-line comments
Variables
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
Cannot be reassigned and not accessible before they appear within the code.
let
Similar to const, however, let variable can be reassigned but not re-declared.
Data Types
var age = 23
Numbers
var x
Variables
WebsiteSetup.org - Beginner’s Javascript Cheat Sheet 2