Javascript Basic : The things you have to know
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 :
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:
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 :
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 :
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 :
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 :
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 :
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 :
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 :
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 :
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.