JavaScript Cheat sheet Superior programmer

JavaScript cheat sheets will work as memory refreshing tools while developing a website. A JavaScript cheat sheet provides simple, brief instruction for executing JavaScript on a web page.It will help you to get started with JavaScript and let you know what all the things you can do with it. Here at Template’s website builder. Let’s explore some of the best JavaScript cheat sheets listed below.

Combine elements of an array into a single string and return the string

Functions

function name(parameter1, parameter2, parameter3){//what the function does}

If/ Else

if (condition) {

//what to do if condition is met

}else {

//what to do if condition is not met

}

Objects

var person ={

firstName: “John”,

lastName: “Doe”,

age:20,

nationality:”German”

};

Variables

var a;                                     // variable

var b = “init”                          // string

var c = “Hi” + ” ” +” Joe”       // Hi Joe

var d= 1 + 2+”3″                   // “33”

var e = [2,3,4,5]                   // array

var f = false                         // boolean

Const PI = 3.14                  //constant

var a = 1, b = 2,                  // one line

let z = ‘zzz’                        // block scope

Var, let

Can be reassigned

Const

Cannot be reassigned

Basics

On Page Script

<script type = “text/javascript”> … </script>

Comments

//

Single line comments

/* Comment here * /

Multi-line comments

Edit Dom Element

document.get ElementbyId(“element ID”).innerHTML=”Hello World”;

Arrays

var fruits = [“Banana”, “Apple”, “Pear”];

Array Methods

fruits.shift()

Remove the first element of an array

fruits.slice ()

Pulls a copy of a portion of an array into a new array of 4 24

fruits.sort()

Sorts elements alphabetically

fruits.splice()

Adds elements in a specified way and position

fruits.toString()

Converts elements to strings

fruits.unshift()

Adds a new element to the beginning

fruits.valueOf()

Returns the primitive value of the specified object

Loops

for (before loop; condition for loop; execute after loop) {//what to do during the loop}

for – The most common way to create a loop in JavaScript while – Sets up conditions under which a loop executes

do while _ Similar to the while loop but it executes at least once and performs a check at the end to see if the condition is met to execute again

break _ Used to stop and exit the cycle at certain conditions

continue _ Skip parts of the cycle if certain conditions are met

Operators

Basic Operator

+       Addition

–       Subtraction

*       Multiplication

/       Division

()     Grouping operator

%    Modulus (remainder)

++   increment numbers

– –    Decrement numbers

Bitwise Operators

&  AND Statement

I   OR statement

~ NOT

^  XOR

« Left shift

» Right shift

>>>  Zero fill right shift

Comparison Operators

= = Equal to

= = = Equal value & type

! = Not equal

!= =Not equal value/type

> Greater than

< Less than

>/ Greater than or equal to

</ Less than or equal to

? Ternary operator

Events

Mouse

onclick, oncontextmenu, ondblclick, onmousedown,onmouseenter, 

onmouseleave, onmousemove,onmouseover, onmouseout, onmouseup.

Keyboard

onkeydown, onkeypress, onkeyup

Frame

onabort, onbeforeunload, onerror,onhashchange, onload, onpagehide, onpageshow, onresize, onscroll

Drag

ondrag, ondragend, ondragenter, ondragleave, ondragover, ondragstart, ondrop

Clipboard

oncopy, oncut, onpaste

Media

onabort, onended, onerror, onpause, onplay, onplaying, onvolumechange,  onseeking, onratechange

Array Methods

fruits.concat ()

Join several arrays into one

fruits.index0f ()

Returns the first position at which a given element appears in an array

fruits .join()

Combine elements of an array into a single string and return the string

fruits.lastIndexOf()

Gives the last position at which a given element appears in an array

fruits.push()

Add a new element at the end

fruits.reverse()

Reverse the order of the elements in an array

Leave a Reply

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