JavaScript Cheat Sheet (.pdf version available)

In Life Trends

There are good causes to compile a JavaScript cheat sheet. The programming language is changing into more and more extra vital. Many massive Internet firms like Facebook use it as part of their expertise stack.

  • JavaScript is an open supply and thus freely obtainable
  • It works effectively with different fundamental net expertise like HTML and CSS (for which we even have cheat sheets, in addition to for jQuery)
  • JavaScript is a client-side language, which implies it affords quick efficiency for the tip customers
  • It’s a comparatively straightforward but versatile language

For these and another causes, it’s not a shock that JavaScript is the preferred programming language within the Stack Overflow survey 2017.

javascript cheat sheet

JavaScript Cheat Sheet

JavaScript Basics

Let’s begin off with the fundamentals – how to include JavaScript in an internet site.

Including JavaScript in an HTML Page

To include JavaScript inside a web page, you want to wrap it in <script> tags:

<script kind="text/javascript">

//JS code goes right here


With this enter, the browser can determine and execute the code correctly.

Call an External JavaScript File

You may place JavaScript in its personal file and title it inside your HTML. That method, you’ll be able to preserve several types of code separate from each other, making for better-organized information. If your code is in a file known as myscript.js, you’ll name it:

<script src=""></script>

Including Comments

Comments are vital as a result of they assist different people perceive what’s going on in your code or remind you in case you forgot one thing your self. Keep in thoughts that they’ve to be marked correctly so the browser received’t attempt to execute them.

In JavaScript you may have two completely different choices:

  • Single-line feedback — To include a remark that’s restricted to a single line, precede it with //
  • Multi-line feedback — In case you need to write longer feedback between a number of traces, wrap it in /* and */ to keep away from it from being executed

Variables in JavaScript

Variables are stand-in values that you need to use to carry out operations. You must be conversant in them from math class.

var, const, let

You have three completely different potentialities for declaring a variable in JavaScript, every with their very own specialties:

  • var — The most typical variable. Can be reassigned however solely accessed inside a operate. Variables outlined with var transfer to the highest when the code is executed.
  • const — Can not be reassigned and never accessible earlier than they seem throughout the code.
  • let — Similar to const, the let variable could be reassigned however not re-declared.

Data Types

Variables can comprise several types of values and knowledge varieties. You use = to assign them:

  • Numbers — var age = 23
  • Variables — var x
  • Text (strings) — var a = "init"
  • Operations — var b = 1 + 2 + 3
  • True or false statements — var c = true
  • Constant numbers — const PI = 3.14
  • Objects — var title = {firstName:"John", finalName:"Doe"}

There are extra potentialities. Note that variables are case delicate. That means lastname and finalName can be dealt with as two completely different variables.


Objects are sure form of variables. They are variables which may have their very own values and strategies. The latter are actions that you could carry out on objects.

var individual = {

The Next Level: Arrays

Next up in our JavaScript cheat sheet are arrays. Arrays are a part of many alternative programming languages. They are a method of organizing variables and properties into teams. Here’s how to create one in JavaScript:

var fruit = ["Banana", "Apple", "Pear"];

Now you may have an array known as fruit which comprises three objects that you need to use for future operations.

Array Methods

Once you may have created arrays, there are some things you are able to do with them:

  • concat() — Join a number of arrays into one
  • indexOf() — Returns the primitive worth of the required object
  • be a part of() — Combine components of an array right into a single string and return the string
  • finalIndexOf() — Gives the final place at which a given ingredient seems in an array
  • pop() — Removes the final ingredient of an array
  • push() — Add a brand new ingredient on the finish
  • reverse() — Sort components in a descending order
  • shift() — Remove the primary ingredient of an array
  • slice() — Pulls a replica of a portion of an array into a brand new array
  • type() — Sorts components alphabetically
  • splice() — Adds components in a specified method and place
  • toString() — Converts components to strings
  • unshift() —Adds a brand new ingredient to the start
  • valueOf() — Returns the primary place at which a given ingredient seems in an array


If you may have variables, you need to use them to carry out completely different sorts of operations. To achieve this, you want operators.

Basic Operators

  • + — Addition
  • - — Subtraction
  • * — Multiplication
  • / — Division
  • (...) — Grouping operator, operations inside brackets are executed sooner than these outside
  • % — Modulus (the rest )
  • ++ — Increment numbers
  • -- — Decrement numbers

Comparison Operators

  • == — Equal to
  • === — Equal worth and equal kind
  • != — Not equal
  • !== — Not equal worth or not equal kind
  • > — 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 assertion
  • - — OR assertion
  • ~ — NOT
  • ^ — XOR
  • << — Left shift
  • >> — Right shift
  • >>> — Zero fill proper shift


JavaScript features are blocks of code which carry out a sure activity. A fundamental operate appears to be like like this:

operate title(parameter1, parameter2, parameter3) {
    // what the operate does

As you’ll be able to see, it consists the operate key phrase plus a reputation. The operate’s parameters are within the brackets and you’ve got curly brackets round what the operate performs. You can create your individual, however to make your life simpler – there are additionally a variety of default features.

Outputting Data

A typical utility for features is the output of information. For the output, you may have the next choices:

  • alert() — Output knowledge in an alert field within the browser window
  • affirm() — Opens up a sure/no dialog and returns true/false relying on person click on
  • console.log() — Writes info to the browser console, good for debugging functions
  • doc.write() — Write immediately to the HTML doc
  • immediate() — Creates a dialogue for person enter

Global Functions

Global features are features constructed into each browser able to working JavaScript.

  • decodeURI() — Decodes a Uniform Resource Identifier (URI) created by encodeURI or related
  • decodeURIComponent() — Decodes a URI part
  • encodeURI() — Encodes a URI into UTF-8
  • encodeURIComponent() — Same however for URI elements
  • eval() — Evaluates JavaScript code represented as a string
  • isFinite() — Determines whether or not a handed worth is a finite quantity
  • isNaN() — Determines whether or not a price is NaN or not
  • Number() —- Returns a quantity transformed from its argument
  • parseFloat() — Parses an argument and returns a floating level quantity
  • parseInt() — Parses its argument and returns an integer

JavaScript Loops

Loops are a part of most programming languages. They permit you to execute blocks of code desired variety of instances with completely different values:

for (earlier than loop; situation for loop; execute after loop) {
    // what to do in the course of the loop

You have a number of parameters to create loops:

  • for — The most typical method to create a loop in JavaScript
  • whereas — Sets up situations below which aloop executes
  • do whereas — Similar to the whereas loop however it executes at the least as soon as and performs a test on the finish to see if the situation is met to execute once more
  • break —Used to cease and exit the cycle at sure situations
  • proceed — Skip components of the cycle if sure situations are met

IfElse Statements

These forms of statements are straightforward to perceive. Using them, you’ll be able to set situations for when your code is executed. If sure situations apply, one thing is finished, if not – one thing else is executed.

if (situation) {
    // what to do if situation is met
} else {
    // what to do if situation will not be met

An analogous idea to if else is the change assertion. However, utilizing the change you choose certainly one of a number of code blocks to execute.


Strings are what JavaScript calls text that doesn’t carry out a operate however can seem on the display screen.

var individual = "John Doe";

In this case, John Doe is the string.

Escape Characters

In JavaScript, strings are marked with single or double quotes. If you need to use citation marks in a string, you want to use particular characters:

  • ' — Single quote
  • " — Double quote

Aside from that you simply even have extra escape characters:

  • — Backslash
  • b — Backspace
  • f — Form feed
  • n — New line
  • r — Carriage return
  • t — Horizontal tabulator
  • v — Vertical tabulator

String Methods

There are many alternative methods to work with strings:

  • charAt() — Returns a personality at a specified place inside a string
  • charCodeAt() — Gives you the unicode of a personality at that place
  • concat() — Concatenates (joins) two or extra strings into one
  • fromCharCode() — Returns a string created from the required sequence of UTF-16 code items
  • indexOf() — Provides the place of the primary incidence of a specified text inside a string
  • finalIndexOf() — Same as indexOf() however with the final incidence, looking out backward
  • match() — Retrieves the matches of a string in opposition to a search sample
  • change() — Find and change specified text in a string
  • search() — Executes a seek for an identical text and returns its place
  • slice() — Extracts a piece of a string and returns it as a brand new string
  • break up() — Splits a string object into an array of strings at a specified place
  • substr() —  Similar to slice() however extracts a substring relying on a specified variety of characters
  • substring() — Also related to slice() however can’t settle for unfavourable indices
  • toLowerCase() — Convert strings to decrease case
  • toUpperCase() — Convert strings to higher case
  • valueOf() — Returns the primitive worth (that has no properties or strategies) of a string object

Regular Expression Syntax

Regular expressions are search patterns used to match character combos in strings. The search sample can be utilized for text search and text change operations.

Pattern Modifiers

  • e — Evaluate substitute
  • i — Perform case-insensitive matching
  • g — Perform international matching
  • m — Perform a number of line matching
  • s — Treat strings as a single line
  • x — Allow feedback and whitespace within the sample
  • U — Ungreedy sample


  • [abc] — Find any of the characters between the brackets
  • [^abc] — Find any character that are not within the brackets
  • [0-9] — Used to discover any digit from 0 to 9
  • [A-z] — Find any character from uppercase A to lowercase z
  • (a-b-c) — Find any of the options separated with -


  • . — Find a single character, besides newline or line terminator
  • w — Word character
  • W — Non-word character
  • d — A digit
  • D — A non-digit character
  • s — Whitespace character
  • S — Non-whitespace character
  • b — Find a match in the beginning/finish of a phrase
  • B — A match not in the beginning/finish of a phrase
  • — NUL character
  • n — A brand new line character
  • f — Form feed character
  • r — Carriage return character
  • t — Tab character
  • v — Vertical tab character
  • xxx — The character specified by an octal quantity xxx
  • xdd — Character specified by a hexadecimal quantity dd
  • uxxxx — The Unicode character specified by a hexadecimal quantity xxxx


  • n+ — Matches any string that comprises at the least one n
  • n* — Any string that comprises zero or extra occurrences of n
  • n? — A string that comprises zero or one incidence of n
  • n{X} — String that comprises a sequence of X n’s
  • n{X,Y} — Strings that comprise a sequence of X to Y n’s
  • n{X,} — Matches any string that comprises a sequence of at the least X n’s
  • n$ — Any string with n on the finish of it
  • ^n — String with n in the beginning of it
  • ?=n — Any string that’s adopted by a particular string n
  • ?!n — String that’s not adopted by a particular string ni

Numbers and Math

In JavaScript, you can even work with numbers, constants and carry out mathematical features.

Number Properties

  • MAX_VALUE — The most numeric worth representable in JavaScript
  • MIN_VALUE — Smallest constructive numeric worth representable in JavaScript
  • NaN — The “Not-a-Number” worth
  • NEGATIVE_INFINITY — The unfavourable Infinity worth
  • POSITIVE_INFINITY — Positive Infinity worth

Number Methods

  • toExponential() — Returns the string with a rounded quantity written as exponential notation
  • toFixed() — Returns the string of a quantity with a specified variety of decimals
  • toPrecision() — String of a quantity written with a specified size
  • toString() — Returns a quantity as a string
  • valueOf() — Returns a quantity as a quantity

Math Properties

  • E — Euler’s quantity
  • LN2 — The pure logarithm of two
  • LN10 — Natural logarithm of 10
  • LOG2E — Base 2 logarithm of E
  • LOG10E — Base 10 logarithm of E
  • PI — The quantity PI
  • SQRT1_2 — Square root of half of
  • SQRT2 — The sq. root of two

Math Methods

  • abs(x) — Returns absolutely the (constructive) worth of x
  • acos(x) — The arccosine of x, in radians
  • asin(x) — Arcsine of x, in radians
  • atan(x) — The arctangent of x as a numeric worth
  • atan2(y,x) — Arctangent of the quotient of its arguments
  • ceil(x) — Value of x rounded up to its nearest integer
  • cos(x) — The cosine of x (x is in radians)
  • exp(x) — Value of Ex
  • flooring(x) — The worth of x rounded down to its nearest integer
  • log(x) — The pure logarithm (base E) of x
  • max(x,y,z,...,n) — Returns the quantity with the very best worth
  • min(x,y,z,...,n) — Same for the quantity with the bottom worth
  • pow(x,y) — X to the ability of y
  • random() — Returns a random quantity between Zero and 1
  • spherical(x) — The worth of x rounded to its nearest integer
  • sin(x) — The sine of x (x is in radians)
  • sqrt(x) — Square root of x
  • tan(x) — The tangent of an angle

Dealing with Dates in JavaScript

You may work with and modify dates and time with JavaScript. This is the subsequent chapter within the JavaScript cheat sheet.

Setting Dates

  • Date() — Creates a brand new date object with the present date and time
  • Date(2017, 5, 21, 3, 23, 10, 0) — Create a customized date object. The numbers characterize a year, month, day, hour, minutes, seconds, milliseconds. You can omit something you need aside from year and month.
  • Date("2017-06-23") — Date declaration as a string

Pulling Date and Time Values

  • getDate() — Get the day of the month as a quantity (1-31)
  • getDay() —  The weekday as a quantity (0-6)
  • getFullYear() — Year as a four-digit quantity (yyyy)
  • getHours() — Get the hour (0-23)
  • getMilliseconds() — The millisecond (0-999)
  • getMinutes() — Get the minute (0-59)
  • getMonth() —  Month as a quantity (0-11)
  • getSeconds() — Get the second (0-59)
  • getTime() — Get the milliseconds since January 1, 1970
  • getUTCDate() — The day (date) of the month within the specified date in accordance to common time (additionally obtainable for day, month, full year, hours, minutes and so forth.)
  • parse — Parses a string illustration of a date and returns the variety of milliseconds since January 1, 1970

Set Part of a Date

  • setDate() — Set the day as a quantity (1-31)
  • setFullYear() — Sets the year (optionally month and day)
  • setHours() — Set the hour (0-23)
  • setMilliseconds() — Set milliseconds (0-999)
  • setMinutes() — Sets the minutes (0-59)
  • setMonth() — Set the month (0-11)
  • setSeconds() — Sets the seconds (0-59)
  • setTime() — Set the time (milliseconds since January 1, 1970)
  • setUTCDate() — Sets the day of the month for a specified date in accordance to common time (additionally obtainable for day, month, full year, hours, minutes and so forth.)

DOM Mode

The DOM is the Document Object Model of a web page. It is the code of the construction of a webpage. JavaScript comes with quite a lot of other ways to create and manipulate HTML components (known as nodes).

Node Properties

  • attributes — Returns a dwell assortment of all attributes registered to a component
  • baseURI — Provides absolutely the base URL of an HTML ingredient
  • youngsterNodes — Gives a group of a component’s youngster nodes
  • firstChild — Returns the primary youngster node of a component
  • lastChild — The final youngster node of a component
  • nextSibling — Gives you the subsequent node on the similar node tree stage
  • nodeName —Returns the title of a node
  • nodeType —  Returns the kind of a node
  • nodeValue — Sets or returns the worth of a node
  • proprietorDocument — The top-level doc object for this node
  • guardianNode — Returns the guardian node of a component
  • previousSibling — Returns the node instantly previous the present one
  • textContent — Sets or returns the textual content material of a node and its descendants

Node Methods

  • appendChild() — Adds a brand new youngster node to a component because the final youngster node
  • cloneNode() — Clones an HTML ingredient
  • evaluateDocumentPlace() — Compares the doc place of two components
  • getFeature() — Returns an object which implements the APIs of a specified function
  • hasAttributes() — Returns true if a component has any attributes, in any other case false
  • hasChildNodes() — Returns true if a component has any youngster nodes, in any other case false
  • insertBefore() — Inserts a brand new youngster node earlier than a specified, present youngster node
  • isDefaultNamearea() — Returns true if a specified namespaceURI is the default, in any other case false
  • isEqualNode() — Checks if two components are equal
  • isSameNode() — Checks if two components are the identical node
  • isSupported() — Returns true if a specified function is supported on the ingredient
  • lookupNamespaceURI() — Returns the namespace URI related to a given node
  • lookupPrefix() — Returns a DOMString containing the prefix for a given namespace URI, if current
  • normalize() — Joins adjoining text nodes and removes empty text nodes in a component
  • removeChild() — Removes a baby node from a component
  • replaceChild() — Replaces a baby node in a component

Element Methods

  • getAttribute() — Returns the required attribute worth of a component node
  • getAttributeNS() — Returns string worth of the attribute with the required namespace and title
  • getAttributeNode() — Gets the required attribute node
  • getAttributeNodeNS() — Returns the attribute node for the attribute with the given namespace and title
  • getElementsByTagName() — Provides a group of all youngster components with the required tag title
  • getElementsByTagNameNS() —  Returns a dwell HTMLCollection of components with a sure tag title belonging to the given namespace
  • hasAttribute() — Returns true if a component has any attributes, in any other case false
  • hasAttributeNS() — Provides a real/false worth indicating whether or not the present ingredient in a given namespace has the required attribute
  • removeAttribute() — Removes a specified attribute from a component
  • removeAttributeNS() — Removes the required attribute from a component inside a sure namespace
  • removeAttributeNode() — Takes away a specified attribute node and returns the eliminated node
  • setAttribute() — Sets or modifications the required attribute to a specified worth
  • setAttributeNS() —  Adds a brand new attribute or modifications the worth of an attribute with the given namespace and title
  • setAttributeNode() — Sets or modifications the required attribute node
  • setAttributeNodeNS() — Adds a brand new namespaced attribute node to a component

Working with the User Browser

Besides HTML components, JavaScript can be in a position to bear in mind the person browser and incorporate its properties into the code.

Window Properties

  • closed — Checks whether or not a window has been closed or not and returns true or false
  • defaultStatus — Sets or returns the default text within the standing bar of a window
  • doc — Returns the doc object for the window
  • frames — Returns all <iframe> components within the present window
  • historical past — Provides the History object for the window
  • innerHeight — The interior top of a window’s content material space
  • innerWidth — The interior width of the content material space
  • size — Find out the variety of  <iframe> components within the window
  • location — Returns the placement object for the window
  • title — Sets or returns the title of a window
  • navigator — Returns the Navigator object for the window
  • opener — Returns a reference to the window that created the window
  • outerHeight — The outer top of a window, together with toolbars/scrollbars
  • outerWidth — The outer width of a window, together with toolbars/scrollbars
  • pageXOffset — Number of pixels the present doc has been scrolled horizontally
  • pageYOffset — Number of pixels the doc has been scrolled vertically
  • guardian — The guardian window of the present window
  • display screen — Returns the Screen object for the window
  • display screenLeft — The horizontal coordinate of the window (relative to the display screen)
  • display screenTop — The vertical coordinate of the window
  • screenX — Same as display screenLeft however wanted for some browsers
  • screenY — Same as display screenTop however wanted for some browsers
  • self — Returns the present window
  • standing — Sets or returns the text within the standing bar of a window
  • high — Returns the topmost browser window

Window Methods

  • alert() — Displays an alert field with a message and an OK button
  • blur() — Removes focus from the present window
  • clearInterval() — Clears a timer set with setInterval()
  • clearTimeout() — Clears a timer set with setTimeout()
  • shut() — Closes the present window
  • affirm() — Displays a dialogue field with a message and an OK and Cancel button
  • focus() — Sets focus to the present window
  • moveBy() — Moves a window relative to its present place
  • transferTo() — Moves a window to a specified place
  • open() — Opens a brand new browser window
  • print() — Prints the content material of the present window
  • immediate() — Displays a dialogue field that prompts the customer for enter
  • resizeBy() — Resizes the window by the required variety of pixels
  • resizeTo() — Resizes the window to a specified width and top
  • scrollBy() — Scrolls the doc by a specified variety of pixels
  • scrollTo() — Scrolls the doc to specified coordinates
  • setInterval() — Calls a operate or evaluates an expression at specified intervals
  • setTimeout() — Calls a operate or evaluates an expression after a specified interval
  • cease() — Stops the window from loading

Screen Properties

  • availHeight — Returns the peak of the display screen (excluding the Windows Taskbar)
  • availWidth — Returns the width of the display screen (excluding the Windows Taskbar)
  • colorDepth — Returns the bit depth of the colour palette for displaying photos
  • top — The complete top of the display screen
  • pixelDepth — The coloration decision of the display screen in bits per pixel
  • width — The complete width of the display screen

JavaScript Events

Events are issues that may occur to HTML components and are carried out by the person. The programming language can hear for these occasions and set off actions within the code. No JavaScript cheat sheet can be full with out them.


  • onclick — The occasion happens when the person clicks on a component
  • oncontextmenu — User right-clicks on a component to open a context menu
  • ondblclick — The person double-clicks on a component
  • onmousedown — User presses a mouse button over a component
  • onmouseenter — The pointer strikes onto a component
  • onmouseleave — Pointer strikes out of a component
  • onmousemove — The pointer is transferring whereas it’s over a component
  • onmouseover — When the pointer is moved onto a component or certainly one of its kids
  • onmouseout — User strikes the mouse pointer out of a component or certainly one of its kids
  • onmouseup — The person releases a mouse button whereas over a component


  • onkeydown — When the person is urgent a key down
  • onkeypress — The second the person begins urgent a key
  • onkeyup — The person releases a key


  • onabort — The loading of a media is aborted
  • onbeforeunload — Event happens earlier than the doc is about to be unloaded
  • onerror — An error happens whereas loading an exterior file
  • onhashchange — There have been modifications to the anchor a part of a URL
  • onload — When an object has loaded
  • onpagehide — The person navigates away from a webpage
  • onpageshow — When the person navigates to a webpage
  • onresize — The doc view is resized
  • onscroll — An ingredient’s scrollbar is being scrolled
  • onunload — Event happens when a web page has unloaded


  • onblur — When a component loses focus
  • onchange — The content material of a type ingredient modifications (for <enter>, <choose> and <textarea>)
  • onfocus — An ingredient will get focus
  • onfocusin — When a component is about to get focus
  • onfocusout — The ingredient is about to lose focus
  • oninput — User enter on a component
  • oninvalid — An ingredient is invalid
  • onreset — A type is reset
  • onsearch — The person writes one thing in a search discipline (for <enter="search">)
  • onselect — The person selects some text (for <enter> and <textarea>)
  • onsubmit — A type is submitted


  • ondrag — An ingredient is dragged
  • ondragend — The person has completed dragging the ingredient
  • ondragenter — The dragged ingredient enters a drop goal
  • ondragleave — A dragged ingredient leaves the drop goal
  • ondragover — The dragged ingredient is on high of the drop goal
  • ondragstart — User begins to drag a component
  • ondrop — Dragged ingredient is dropped on the drop goal


  • oncopy — User copies the content material of a component
  • oncut — The person cuts a component’s content material
  • onpaste — A person pastes content material in a component


  • onabort — Media loading is aborted
  • oncanplay — The browser can begin enjoying media (e.g. a file has buffered sufficient)
  • oncanplaythrough — The browser can play by means of media with out stopping
  • ondurationchange — The period of the media modifications
  • onended — The media has reached its finish
  • onerror — Happens when an error happens whereas loading an exterior file
  • onloadeddata — Media knowledge is loaded
  • onloadedmetadata — Metadata (like dimensions and period) are loaded
  • onloadstart —  The browser begins searching for specified media
  • onpause — Media is paused both by the person or routinely
  • onplay — The media has been began or is now not paused
  • onplaying — Media is enjoying after having been paused or stopped for buffering
  • onprogress — The browser is within the strategy of Downloading the media
  • onratechange — The enjoying velocity of the media modifications
  • onseeked — User is completed transferring/skipping to a brand new place within the media
  • onseeking — The person begins transferring/skipping
  • onstalled — The browser is making an attempt to load the media however it’s not obtainable
  • onsuspend — The browser is deliberately not loading media
  • ontimeupdate — The enjoying place has modified (e.g. due to quick ahead)
  • onvolumechange — Media quantity has modified (together with mute)
  • onwaiting — Media paused however anticipated to resume (for instance, buffering)


  • animationend — A CSS animation is full
  • animationiteration — CSS animation is repeated
  • animationstart — CSS animation has began


  • transitionend — Fired when a CSS transition has accomplished
  • onmessage — A message is obtained by means of the occasion supply
  • onoffline — The browser begins to work offline
  • ononline — The browser begins to work on-line
  • onpopstate — When the window’s historical past modifications
  • onshow — A <menu> ingredient is proven as a context menu
  • onstorage — A Web Storage space is up to date
  • ontoggle — The person opens or closes the <particulars> ingredient
  • onwheel — Mouse wheel rolls up or down over a component
  • ontouchcancel — Screen-touch is interrupted
  • ontouchend — User’s finger is faraway from a touch-screen
  • ontouchmove — A finger is dragged across the display screen
  • ontouchstart — A finger is placed on the touch-screen


When working with JavaScript, completely different errors can happen. There are a number of methods of dealing with them:

  • attempt — Lets you outline a block of code to check for errors
  • catch — Set up a block of code to execute in case of an error
  • throw — Create customized error messages as an alternative of the usual JavaScript errors
  • lastly — Lets you execute code, after try to catch, whatever the outcome

Error Name Values

JavaScript additionally has a built-in error object. It has two properties:

  • title — Sets or returns the error title
  • message — Sets or returns an error message in string from

The error property can return six completely different values as its title:

  • EvalError — An error has occurred within the eval() operate
  • VaryError — A quantity is “out of range”
  • ReferenceError — An unlawful reference has occurred
  • SyntaxError — A syntax error has occurred
  • KindError — A kind error has occurred
  • URIError — An encodeURI() error has occurred

The JavaScript Cheat Sheet in a Nutshell

JavaScript is gaining a lot significance as a programming language. It is more and more the go-to language for constructing net properties thanks to its confirmed observe document and advantages.

In the JavaScript cheat sheet above, now we have compiled lots of the most simple and vital operators, features, rules, and strategies. It gives a great overview of the language and a reference for each builders and learners. We hope you may have discovered it helpful.

Do you may have additions to the JavaScript cheat sheet? Please tell us within the feedback part beneath!