Javascript cheatsheet.
Methods, functions and events.
Methods, functions and events.
Javascript methods are actions that can be performed on objects. A JavaScript method is a property containing a function definition.
Objects, Strings, RegEx, Arrays, Number & Date
Examples for each to help understand the many types of JS methods available natively.
toString
You've got a number, you want to turn it into a string…
toLocaleString
To handle date formatting for all countries you can convert the date from the computed format into locale formats.
valueOf
Return the primitive value of a string object.
hasOwnProperty
The hasOwnProperty() method returns a boolean indicating whether the object has the specified property as its own property (as opposed to inheriting it). What does this mean?
isPrototypeOf
What do we use this for then?
"The isPrototypeOf() method provides a way to determine if one object is the prototype of another. This technique can be used to determine the class of an object."
propertyIsEnumerable
Enumerable /ɪˈnjuːm(ə)rəb(ə)l/
adjective
able to be counted by one-to-one correspondence with the set of all positive integers.
I'm not sure that helps me understand it. There is a tl;dr explanation and many resources online to get bored of. But below I'll try and demo a simple version of what it means.
charAt
Find out what character is where in a string. Good for finding out the first or last character of a word / sentence / series of characters.
concat
There are some resources online about efficiency of different techniques to concatinate your code. The new ES6 backtick method has introduced a clear, human-readable, syntax which outshines using concat(). MDN even specifies in the documentation to use other methods to concatinate.
indexOf
Use this to find a match from one item to an item inside an array. I use this a fair amount when trying to find out whether a value is contained in a list of values.
lastIndexOf
This gets the starting character number of the string you pass into the lastIndexOf() method.
match
The match() method retrieves the result of matching a string against a regular expression.
replace
We can replace strings where we need using this argument, we can also use RegEx to target specific characters or words in a string
slice
The slice() method extracts a section of a string and returns it as a new string, without modifying the original string.