Javascript Basic : The things you have to know

Shajjad Abir
4 min readMay 5, 2021

1. String.charAt()

From the specified index, this method returns the character. Index number starts from 0 and goes to the length of the string-1. The index value can’t be a negative, greater than, or equal to the length of the string.

Syntax : string.charAt(index);

Example :

Expected Output : The character of the sentence at index 12 is : ‘S’

The index of the last character in a string is string. length — 1, the second last character is a string. length — 2, and so on:

Expected Output : The character of the sentence at index 6 from last : ‘a’

2. String.Concat()

To join two or more strings this string. concat() method is used.

Generally, this method is used to calling strings and returns a new string that concatenates the string arguments.

Syntax : string.concat(str1,str2,…,strN)

Example :

Output : ‘My favorite programming language is the Javascript.’

3. String.startsWith()

The startsWith() method is used to see if your desired string starts with a specific character or character set. It always returns a Boolean value true or false

Syntax: string.startsWith(searchString)

Example :

code snippet of startsWith() method

4. String.endsWith()

String.endsWith() method is used to see if your desired string ends with a specific character or character set. It also always returns a Boolean value of true or false

Syntax : string.endsWith(searchString)

Example :

code snippet of endsWith() method demo

5. String.includes()

It is to find out whether a string carries the characters of a specified string. The includes() method is also case sensitive.

Syntax : string.includes(searchString)

Example :

code snippet of includes() method

6. Math.random()

Math. random() method is to generate random numbers. This method does not take any arguments. However, it returns a floating-point that only outputs any number from 0 to 1. That means it just generates random numbers. But that number will be from 0 to 1.

But this way it will give a number from 0 to 1 at a time. But now if we want bigger numbers, we have to do a little trick, multiply the whole number by the number you want. Suppose we want a random number within 50.

Example :

code snippet of Math.random() method

By using Math.floor() method with this random method, we can get a random integer number.

7. Math.abs()

Math.abs() method returns the absolute value of a number.

Syntax : Math.abs(x)

Example :

code snippet of Math.abs() method

8. Array.map()

Array. map() methods help make programs far more convenient and useful.It is used to get a modified version of the array. It doesn’t change the original array.

When calling a map array, it will apply a function assigned to each element in that array, and eventually, return them all as a new array.

Syntax : array.map(function(currentValue, index, arr), thisValue)

Example :

code snippet of map() method

9. Array.join()

The array. join() method combines all elements of an array and returns as a string. This method will not change the original array. A specified separator and default value comma separate the string items.

Syntax : array.join(separator)

Example :

The elements will be separated by a specified separator. The default separator is comma (,).

10. Number.parseInt()

A string argument parses by parseInt method which returns an integer. It returns NaN when its value cannot be converted into a number.

Syntax : Number.parseInt(string, radix)

Example :

code snippet of parseInt() method

--

--