JavaScript Cheat Sheet: A Comprehensive List for Quick Reference

Welcome to the “JavaScript Cheat Sheet: A Comprehensive List for Quick Reference.” This cheat sheet serves as a valuable resource for both beginners and experienced developers. It provides a comprehensive collection of JavaScript syntax, functions, methods, and best practices.

With this cheat sheet, you can quickly find and review essential concepts like variables, data types, control structures, functions, arrays, objects, DOM manipulation, and more. Whether you’re building websites, web applications, or server-side applications with Node.js, this cheat sheet will be your handy reference. It’s concise, visually appealing, and designed for easy comprehension. Explore the “JavaScript Cheat Sheet” and enhance your JavaScript coding skills.

Table of Contents

  1. Basics
  2. Variables
  3. Data Types
  4. Strings
  5. Numbers and Math
  6. Arrays
  7. Dates
  8. JSON
  9. Regular Expressions
  10. If-Else
  11. Loops
  12. Global Functions
  13. Events
  14. Promises
  15. Errors

1. Basics

On page script:

Include external JS file:

Delay – 1 second timeout:

Functions:

Edit DOM element:

Output:

Comments:

2. Variables

Strict mode:

Values:

Operators:

Bitwise operators:

Arithmetic:

3. Data Types

Objects:

4. Strings

5. Numbers and Math

Math:

  • Constants like Math.PI:
    E, PI, SQRT2, SQRT1_2, LN2, LN10, LOG2E, Log10E

6. Arrays

Methods:

concat, copyWithin, every, fill, filter, find, findIndex, forEach, indexOf, isArray, join, lastIndexOf, map, pop, push, reduce, reduceRight, reverse, shift, slice, some, sort, splice, toString, unshift, valueOf

7. Dates

Get Times:

Setting part of a date:

8. JSON

Send:

Storing and retrieving:

9. Regular Expressions

Modifiers:

Patterns:

10. If-Else

Switch Statement:

11. Loops

For Loop:

While Loop:

Do While Loop:

Break:

Continue:

12. Global Functions

13. Events

  • Mouse
    onclick, oncontextmenu, ondblclick, onmousedown, onmouseenter, onmouseleave, onmousemove, onmouseover, onmouseout, onmouseup
  • Keyboard
    onkeydown, onkeypress, onkeyup
  • Frame
    onabort, onbeforeunload, onerror, onhashchange, onload, onpageshow, onpagehide, onresize, onscroll, onunload
  • Form
    onblur, onchange, onfocus, onfocusin, onfocusout, oninput, oninvalid, onreset, onsearch, onselect, onsubmit
  • Drag
    ondrag, ondragend, ondragenter, ondragleave, ondragover, ondragstart, ondrop
  • Clipboard
    oncopy, oncut, onpaste
  • Media
    onabort, oncanplay, oncanplaythrough, ondurationchange, onended, onerror, onloadeddata, onloadedmetadata, onloadstart, onpause, onplay, onplaying, onprogress, onratechange, onseeked, onseeking, onstalled, onsuspend, ontimeupdate, onvolumechange, onwaiting
  • Animation
    animationend, animationiteration, animationstart
  • Miscellaneous
    transitionend, onmessage, onmousewheel, ononline, onoffline, onpopstate, onshow, onstorage, ontoggle, onwheel, ontouchcancel, ontouchend, ontouchmove, ontouchstart

14. Promises

  • States
    pending, fulfilled, rejected
  • Properties
    Promise.length, Promise.prototype
  • Methods
    Promise.all(iterable), Promise.race(iterable), Promise.reject(reason), Promise.resolve(value)

15. Errors

Throw error:

Input validation:

Error name values:

I hope you find this article helpful.
Thank you for reading. Happy Coding..!! 🙂

If you found value in this article,
you can support us by buying me a coffee! ☕

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *