Mohammad Fahad
3 min readNov 2, 2020

--

Photo by Irvan Smith on Unsplash

Some fundamentals of JavaScript

STRING:

1. charAt()

This method of JavaScript returns the position of a letter inside a string,

just by providing an index number. It starts counting from 0.

Interestingly it also counts white spaces.

If the value provided does not exist in the string, it returns “an empty string”.

2. includes()

In this method we can check, whether the existence of the provided string is

there in the string or not, returning true or false. As this method is case sensitive one must

be sure of his/her implementation of this method.

3. trim()

This method works like a trimmer, when used, it removes all the white spaces from both ends.

Trim does not affect the value of the string itself.

MATH:

4. parseFloat()

This function converts an argument to a number from a string(if needed) and returns a floating-point number.

It is a function property of the global object. If there are any unexpected* characters it will return NaN.

This method can also parse and return infinity.

Unexpected characters eg: [ + — and even an extra decimal point].

5. parseInt()

This function parses a string and returns a number. It is discouraged to use this method when there is

a very large or very small number instead of using Math.floor().

If the number is like 7.85e23 (7.85 * 10 to the power 23) it will return unexpected results.

6. Math.ceil()

This function will round up the number and return its next largest integer. If NaN is given as a value it returns 0, not a NaN error.

Because ceil() is a static method of Math, you always use it as Math.ceil(), rather than as a method of a Math object you created (Math is not a constructor).

7. Math.random()

The JavaScript Math.random() method is an excellent built-in method for producing random numbers. When Math.random() is executed,

it returns a random number that can be anywhere between 0 and 1. This process works fine even if you set its max and min value in it, as an example, you can generate a four-digit number.

ARRAY:

8. map()

The map() method creates a new array populated with the results of calling a provided function on every element in the calling array.

9. reverse()

This method reverses an array, for example, the first element becomes the last and the last becomes the first.

10. splice()

This method takes three-parameter, first for the targeted index number, second for how many items you want to delete/update or replace and the third parameter is what you want to insert.

--

--

Mohammad Fahad

Innovative and Detail-Oriented Frontend Developer trying to write some articles as a hobby!