JavaScript in an HTML Page
CHEAT SHEET
<script type="text/javascript">
//JS code goes here
</script>
Call an External JavaScript
File
<script src="myscript.js">
</script>
Go to website Go to website
Including Comments
Single-line comments: //
Multi-line comments : /* and */
Go to website
Variables
var
const
let
Go to website
D e s i g n b y a n y t h i n g p r o g r a m m i n g . c o m
Data Types
Go to website
Objects
Go to website
strings
numbers
booleans
undefined
ull.
var person = {
firstName:"John",
lastName:"Doe",
age:20,
nationality:"German"
};
Arrays
Go to website
Array Methods
Go to website
var fruit = [
"Banana",
"Apple",
"Pear"];
var fruit = ["Banana", "Apple",
"Pear"];
OR
concat()
indexOf()
join()
lastIndexOf()
pop()
push()
reverse()
shift()
slice()
sort()
splice()
toString()
unshift()
valueOf()
D e s i g n b y a n y t h i n g p r o g r a m m i n g . c o m
Operators Operators
Basic Operators Basic Operators
+ — Addition
- — Subtraction
* — Multiplication
/ — Division
(...) — Grouping operator,
% — Modulus (remainder )
++ — Increment numbers
-- — Decrement numbers
Go to website
Operators Operators
Comparison Operators
== — Equal to
=== — Equal value and equal type
!= — Not equal
!== — Not equal value or not equal type
> — Greater than
< — Less than
>= — Greater than or equal to
<= — Less than or equal to
? — Ternary operator
Logical Operators
&& — Logical and
|| — Logical or
! — Logical not
Go to website
Go to website Go to website
D e s i g n b y a n y t h i n g p r o g r a m m i n g . c o m
Operators Functions
Outputting Data Global Functions
Bitwise Operators
& — AND statement
| — OR statement
~ — NOT
^ — XOR
<< — Left shift
>> — Right shift
>>> — Zero fill right shift
function name(parameter1, parameter2,
parameter3) {
// what the function does
}
alert()
confirm()
console.log()
document.write()
prompt()
decodeURI()
decodeURIComponent()
encodeURI()
encodeURIComponent()
eval()
isFinite()
isNaN()
D e s i g n b y a n y t h i n g p r o g r a m m i n g . c o m
Loops Conditional Statement
Strings Strings
For
While
Do While
Break
Continue
If Statement
If...Else Statement
Switch Case**
Escape Characters
' — Single quote
" — Double quote
 — Backslash
b — Backspace
f — Form feed
Escape Characters
n — New line
r — Carriage return
t — Horizontal tabulator
v — Vertical tabulator
D e s i g n b y a n y t h i n g p r o g r a m m i n g . c o m
String Methods String Methods
Numbers Numbers
charAt()
charCodeAt()
concat()
fromCharCode()
indexOf()
lastIndexOf()
match()
replace()
search()
Slice()
Split()
substr()
substring()
toLowerCase()
toUpperCase()
Number Properties
MAX_VALUE
MIN_VALUE
NaN
NEGATIVE_INFINITY
POSITIVE_INFINITY
Number Methods
toExponential()
toFixed()
toPrecision()
toString()
valueOf()
D e s i g n b y a n y t h i n g p r o g r a m m i n g . c o m
Pulling Date and Time
Values
Pulling Date and Time
Values
getDate())
getDay()
getFullYear()
getHours()
getMilliseconds()
getMinutes()
getMonth()
getSeconds()
getTime()
getUTCDate()
parse()
Set Part of a Date DOM
setDate()
setFullYear()
setHours()
setMilliseconds()
setMinutes()
setMonth()
setSeconds()
setTime
DOM Properties
attributes()
baseURI()
childNodes()
firstChild()
lastChildnext()
Siblingnode()
Namenode()
D e s i g n b y a n y t h i n g p r o g r a m m i n g . c o m
DOM DOM
DOM DOM
DOM Methods
appendChild()
cloneNode()
compareDocumentPosition()
getFeature()
hasAttributes()
hasChildNodes()
insertBefore()
DOM Methods
isDefaultNamespace()
isEqualNode()
isSameNode()
isSupported()
lookupNamespaceURI()
lookupPrefix()
normalize()
Element Methods
getAttribute()
getAttributeNS()
getAttributeNode()
getAttributeNodeNS()
getElementsByTagName()
Element Methods
getElementsByTagNameNS()
hasAttribute()
hasAttributeNS()
removeAttribute()
removeAttributeNS()
removeAttributeNod()
esetAttribute()
D e s i g n b y a n y t h i n g p r o g r a m m i n g . c o m
Window Properties Window Methods
alert()
blur()
clear Interval()
clear Timeout()
confirm()
focus()
moveBy()
moveToprint()
Events Events
onkeydown()
onkeypress()
onkeyup()
closed()
defaultStatus()
document()
frames()
history()
innerHeight()
innerWidth()
onclick()
oncontextmenu()
ondblclick()
onmousedown()
onmouseenter()
onmouseleave()
onmousemove()
onmouseover()
Mouse Event Keyboard Event
D e s i g n b y a n y t h i n g p r o g r a m m i n g . c o m
Frame Form
onabort
onbeforeunload
onerror
onhashchange
onload
onpagehide
onpageshow
onscroll
onblur
onchange
onfocus
onfocusin
onfocusout
oninput
oninvalid
onreset
onsearch
Media Animation
onabort
oncanplay
oncanplaythrough
ondurationchange
onended
onerror
onloadeddata
animationend
animationiteration
animationstart
D e s i g n b y a n y t h i n g p r o g r a m m i n g . c o m
Errors Others
Others Others
try
catch
throw
finally
transitionend
onmessage
onoffline
ononline
onpopstate
onshow
onstorage
ontoggle
onwheel
ontouchcancel
ontouchend
ontouchmoveo
ntouchstart
EvalError
RangeError
ReferenceError
SyntaxError
TypeError
URIError
D e s i g n b y a n y t h i n g p r o g r a m m i n g . c o m
Visit our Webpage for
more cheats
https://www.anythingprogramming.com

JAVASCRIPT CHEAT SHEET PDF

  • 1.
    JavaScript in anHTML Page CHEAT SHEET <script type="text/javascript"> //JS code goes here </script> Call an External JavaScript File <script src="myscript.js"> </script> Go to website Go to website Including Comments Single-line comments: // Multi-line comments : /* and */ Go to website Variables var const let Go to website D e s i g n b y a n y t h i n g p r o g r a m m i n g . c o m
  • 2.
    Data Types Go towebsite Objects Go to website strings numbers booleans undefined ull. var person = { firstName:"John", lastName:"Doe", age:20, nationality:"German" }; Arrays Go to website Array Methods Go to website var fruit = [ "Banana", "Apple", "Pear"]; var fruit = ["Banana", "Apple", "Pear"]; OR concat() indexOf() join() lastIndexOf() pop() push() reverse() shift() slice() sort() splice() toString() unshift() valueOf() D e s i g n b y a n y t h i n g p r o g r a m m i n g . c o m
  • 3.
    Operators Operators Basic OperatorsBasic Operators + — Addition - — Subtraction * — Multiplication / — Division (...) — Grouping operator, % — Modulus (remainder ) ++ — Increment numbers -- — Decrement numbers Go to website Operators Operators Comparison Operators == — Equal to === — Equal value and equal type != — Not equal !== — Not equal value or not equal type > — Greater than < — Less than >= — Greater than or equal to <= — Less than or equal to ? — Ternary operator Logical Operators && — Logical and || — Logical or ! — Logical not Go to website Go to website Go to website D e s i g n b y a n y t h i n g p r o g r a m m i n g . c o m
  • 4.
    Operators Functions Outputting DataGlobal Functions Bitwise Operators & — AND statement | — OR statement ~ — NOT ^ — XOR << — Left shift >> — Right shift >>> — Zero fill right shift function name(parameter1, parameter2, parameter3) { // what the function does } alert() confirm() console.log() document.write() prompt() decodeURI() decodeURIComponent() encodeURI() encodeURIComponent() eval() isFinite() isNaN() D e s i g n b y a n y t h i n g p r o g r a m m i n g . c o m
  • 5.
    Loops Conditional Statement StringsStrings For While Do While Break Continue If Statement If...Else Statement Switch Case** Escape Characters ' — Single quote " — Double quote — Backslash b — Backspace f — Form feed Escape Characters n — New line r — Carriage return t — Horizontal tabulator v — Vertical tabulator D e s i g n b y a n y t h i n g p r o g r a m m i n g . c o m
  • 6.
    String Methods StringMethods Numbers Numbers charAt() charCodeAt() concat() fromCharCode() indexOf() lastIndexOf() match() replace() search() Slice() Split() substr() substring() toLowerCase() toUpperCase() Number Properties MAX_VALUE MIN_VALUE NaN NEGATIVE_INFINITY POSITIVE_INFINITY Number Methods toExponential() toFixed() toPrecision() toString() valueOf() D e s i g n b y a n y t h i n g p r o g r a m m i n g . c o m
  • 7.
    Pulling Date andTime Values Pulling Date and Time Values getDate()) getDay() getFullYear() getHours() getMilliseconds() getMinutes() getMonth() getSeconds() getTime() getUTCDate() parse() Set Part of a Date DOM setDate() setFullYear() setHours() setMilliseconds() setMinutes() setMonth() setSeconds() setTime DOM Properties attributes() baseURI() childNodes() firstChild() lastChildnext() Siblingnode() Namenode() D e s i g n b y a n y t h i n g p r o g r a m m i n g . c o m
  • 8.
    DOM DOM DOM DOM DOMMethods appendChild() cloneNode() compareDocumentPosition() getFeature() hasAttributes() hasChildNodes() insertBefore() DOM Methods isDefaultNamespace() isEqualNode() isSameNode() isSupported() lookupNamespaceURI() lookupPrefix() normalize() Element Methods getAttribute() getAttributeNS() getAttributeNode() getAttributeNodeNS() getElementsByTagName() Element Methods getElementsByTagNameNS() hasAttribute() hasAttributeNS() removeAttribute() removeAttributeNS() removeAttributeNod() esetAttribute() D e s i g n b y a n y t h i n g p r o g r a m m i n g . c o m
  • 9.
    Window Properties WindowMethods alert() blur() clear Interval() clear Timeout() confirm() focus() moveBy() moveToprint() Events Events onkeydown() onkeypress() onkeyup() closed() defaultStatus() document() frames() history() innerHeight() innerWidth() onclick() oncontextmenu() ondblclick() onmousedown() onmouseenter() onmouseleave() onmousemove() onmouseover() Mouse Event Keyboard Event D e s i g n b y a n y t h i n g p r o g r a m m i n g . c o m
  • 10.
  • 11.
  • 12.
    Visit our Webpagefor more cheats https://www.anythingprogramming.com