
















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
JavaScript cheat sheet for beginners: Variables, Operators, Functions, If - Else Statements, Regular Expression Syntax and so on.
Typology: Cheat Sheet
1 / 24
This page cannot be seen from the preview
Don't miss anything!

















#################
True or fase statements โ var c = true Constant numbers โ const PI = 3. Objects โ var name = {firstName:"John", lastName:โDoe"}
var person = { firstName:"John", lastName:"Doe", age:20, nationality:"German" };
var fruit = ["Banana", "Apple", "Pear"];
concat() โ Join several arrays into one indexOf() โ Returns the primitive value of the specified object join() โ Combine elements of an array into a single string and return the string lastIndexOf() โ Gives the last position at which a given element appears in an array pop() โ Removes the last element of an array push() โ Add a new element at the end reverse() โ Sort elements in descending order shift() โ Remove the first element of an array slice() โ Pulls a copy of a portion of an array into a new array
sort() โ Sorts elements alphabetically splice() โ Adds elements in a specified way and position toString() โ Converts elements to strings unshift() โ Adds a new element to the beginning valueOf() โ Returns the first position at which a given element appears in an array
== โ 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
document.write() โ Write directly to the HTML document prompt() โ Creates an dialogue for user input
decodeURI() โ Decodes a Uniform Resource Identifier (URI) created by encodeURI or similar decodeURIComponent() โ Decodes a URI component encodeURI() โ Encodes a URI into UTF- encodeURIComponent() โ Same but for URI components eval() โ Evaluates JavaScript code represented as a string isFinite() โ Determines whether a passed value is a finite number isNaN() โ Determines whether a value is NaN or not Number() โ Returns a number converted from its argument parseFloat() โ Parses an argument and returns a floating point number parseInt() โ Parses its argument and returns an integer
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 aloop executes do while โ Similar to the while loop, however, 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
if (condition) { // what to do if condition is met } else { // what to do if condition is not met }
var person = "John Doe";
' โ Single quote " โ Double quote \ โ Backslash \b โ Backspace \f โ Form feed \n โ New line \r โ Carriage return \t โ Horizontal tabulator \v โ Vertical tabulator
charAt() โ Returns a character at a specified position inside a string charCodeAt() โ Gives you the unicode of character at that position concat() โ Concatenates (joins) two or more strings into one
x โ Allow comments and whitespace in pattern U โ Ungreedy pattern
[abc] โ Find any of the characters between the brackets [^abc] โ Find any character not in the brackets [0-9] โ Used to find any digit from 0 to 9 [A-z] โ Find any character from uppercase A to lowercase z (a|b|c) โ Find any of the alternatives separated with |
. โ Find a single character, except 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 at the beginning/end of a word \B โ A match not at the beginning/end of a word \0 โ NUL character \n โ A 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 number xxx
\xdd โ Character specified by a hexadecimal number dd \uxxxx โ The Unicode character specified by a hexadecimal number xxxx
n+ โ Matches any string that contains at least one n n* โ Any string that contains zero or more occurrences of n n? โ A string that contains zero or one occurrences of n n{X} โ String that contains a sequence of X nโs n{X,Y} โ Strings that contains a sequence of X to Y nโs n{X,} โ Matches any string that contains a sequence of at least X nโs n$ โ Any string with n at the end of it ^n โ String with n at the beginning of it ?=n โ Any string that is followed by a specific string n ?!n โ String that is not followed by a specific string n
MAX_VALUE โ The maximum numeric value representable in JavaScript MIN_VALUE โ Smallest positive numeric value representable in JavaScript NaN โ The โNot-a-Numberโ value NEGATIVE_INFINITY โ The negative Infinity value POSITIVE_INFINITY โ Positive Infinity value
toExponential() โ Returns a string with a rounded number written as exponential notation
max(x,y,z,...,n) โ Returns the number with the highest value min(x,y,z,...,n) โ Same for the number with the lowest value pow(x,y) โ X to the power of y random() โ Returns a random number between 0 and 1 round(x) โ The value 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
Date() โ Creates a new date object with the current date and time Date(2017, 5, 21, 3, 23, 10, 0) โ Create a custom date object. The numbers represent year, month, day, hour, minutes, seconds, milliseconds. You can omit anything you want except for year and month. Date("2017-06-23") โ Date declaration as a string
getDate() โ Get the day of the month as a number (1-31) getDay() โ The weekday as a number (0-6) getFullYear() โ Year as a four digit number (yyyy) getHours() โ Get the hour (0-23) getMilliseconds() โ The millisecond (0-999) getMinutes() โ Get the minute (0-59) getMonth() โ Month as a number (0-11) getSeconds() โ Get the second (0-59) getTime() โ Get the milliseconds since January 1, 1970
getUTCDate() โ The day (date) of the month in the specified date according to universal time (also available for day, month, fullyear, hours, minutes etc.) parse โ Parses a string representation of a date, and returns the number of milliseconds since January 1, 1970
setDate() โ Set the day as a number (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 according to universal time (also available for day, month, fullyear, hours, minutes etc.)
attributes โ Returns a live collection of all attributes registered to and element baseURI โ Provides the absolute base URL of an HTML element childNodes โ Gives a collection of an elementโs child nodes firstChild โ Returns the first child node of an element lastChild โ The last child node of an element nextSibling โ Gives you the next node at the same node tree level nodeName โ Returns the name of a node
lookupPrefix() โ Returns a DOMString containing the prefix for a given namespaceURI, if present normalize() โ Joins adjacent text nodes and removes empty text nodes in an element removeChild() โ Removes a child node from an element replaceChild() โ Replaces a child node in an element
getAttribute() โ Returns the specified attribute value of an element node getAttributeNS() โ Returns string value of the attribute with the specified namespace and name getAttributeNode() โ Gets the specified attribute node getAttributeNodeNS() โ Returns the attribute node for the attribute with the given namespace and name getElementsByTagName() โ Provides a collection of all child elements with the specified tag name getElementsByTagNameNS() โ Returns a live HTMLCollection of elements with a certain tag name belonging to the given namespace hasAttribute() โ Returns true if an element has any attributes, otherwise false hasAttributeNS() โ Provides a true/false value indicating whether the current element in a given namespace has the specified attribute removeAttribute() โ Removes a specified attribute from an element removeAttributeNS() โ Removes the specified attribute from an element within a certain namespace removeAttributeNode() โ Takes away a specified attribute node and returns the removed node setAttribute() โ Sets or changes the specified attribute to a specified value setAttributeNS() โ Adds a new attribute or changes the value of an attribute with the given namespace and name setAttributeNode() โ Sets or changes the specified attribute node
setAttributeNodeNS() โ Adds a new namespaced attribute node to an element
closed โ Checks whether a window has been closed or not and returns true or false defaultStatus โ Sets or returns the default text in the statusbar of a window document โ Returns the document object for the window frames โ Returns all
setInterval() โ Calls a function or evaluates an expression at specified intervals setTimeout() โ Calls a function or evaluates an expression after a specified interval stop() โ Stops the window from loading
availHeight โ Returns the height of the screen (excluding the Windows Taskbar) availWidth โ Returns the width of the screen (excluding the Windows Taskbar) colorDepth โ Returns the bit depth of the color palette for displaying images height โ The total height of the screen pixelDepth โ The color resolution of the screen in bits per pixel width โ The total width of the screen
onclick โ The event occurs when the user clicks on an element oncontextmenu โ User right-clicks on an element to open a context menu ondblclick โ The user double-clicks on an element onmousedown โ User presses a mouse button over an element onmouseenter โ The pointer moves onto an element onmouseleave โ Pointer moves out of an element onmousemove โ The pointer is moving while it is over an element onmouseover โ When the pointer is moved onto an element or one of its children
onmouseout โ User moves the mouse pointer out of an element or one of its children onmouseup โ The user releases a mouse button while over an element
onkeydown โ When the user is pressing a key down onkeypress โ The moment the user starts pressing a key onkeyup โ The user releases a key
onabort โ The loading of a media is aborted onbeforeunload โ Event occurs before the document is about to be unloaded onerror โ An error occurs while loading an external file onhashchange โ There have been changes to the anchor part of a URL onload โ When an object has loaded onpagehide โ The user navigates away from a webpage onpageshow โ When the user navigates to a webpage onresize โ The document view is resized onscroll โ An elementโs scrollbar is being scrolled onunload โ Event occurs when a page has unloaded
onblur โ When an element loses focus onchange โ The content of a form element changes (for ,