Some important features of Javascript
1.Javascript string charAt()
charAt() is a method of javascript, that specified an index in a string. Let's see the working principle of the charAt() method.
In Picture 1, we declare a string then we have to know the position of any specific character of this string. First, we have to see the position of 0 [position is nothing but an array index ], which means, which character stands in position number 0, we have to know right? But how? Now we can solve it using the charAt() method. We declare 3 variables for knowing the three different characters, or which character is belonging that position, first we declare position_of_0, and simultaneously position_of_1 and position_of_2, we use, “string.charAt(position)” here-string is ‘a’ in picture 1 then the position is 0 , 1 and 2 .
Now we follow the output, ‘I’ is the first output. That means, we put position_of_0 in the first console.log, then it calls the declaration of position_of_0 and which is ‘I’ then we see in the output, It takes little bit space,
Now we follow In picture 1, which character is in position number 1? Most of the people say “a”, But a is not the character which we found the position number “1”, After I , we have a space in the declear string, That string is in the position number ‘1’ . So that we see a blank space in the output, basically it is also a position that counts by chatAt(1).
2.JavaScript String length Property
This image shows, The use case of length. Length is a method that returns the length of a specific string,
Suppose we declare a string type password, If the and we make condition, Of the password is greater than or equal 8, that means if the password is made with more than of minimum 8 character then it will return or show “The password is strong enough” that we already see on the output section.
in this image we see the output is “Te password is too short ”. Why does that happen? That happens because we declare password is less than 8 characters.So password. length is less than 8 characters
3.JavaScript String indexOf() Method
indexOf() one very importent method in javascript string , indexOf() method finds an specific word starts with which index number.
n image 3 , we see the comment declare a string, we have to find which index number is “Hisenberg’s” starting point. Hisenberg starts with “H” and the indexOf() method finds the number of index of a specific keyword.We console it and see the output , Hisenberg starts in the position of 28 number.
4.Using concat() method
It’s a self-explanatory method, this method is contacting 2 string, here I give an example and showing how it works.
here the firstName is “Jessi ” it’s a string, and the second name is “Pinkman ” , [Which is one of the favorite characters of mine btw.] . “Pinkman” is another string. If we can add it using concat() method, Like this , “first_string.concat(second_string)” if we put it on console.log the output will be a single string with no space, For getting space then we have to declare space with a plus sign.
5.Javascript Math object
The Math object is using for completing the mathematical tasks in javascript.
We see Math.PI, when we call math object then default many and more mathematical operation perform using Math object like PI. We got the value of PI.
Some examples of Static property of Math objects.
Math.E = Euler’s constant and the base of natural logarithms. Its value will be 2.718.
Math.LOG2E = Base-2 logarithm of E , approximately value will be 1.443.
And many and more use case available I Math operator. Like this example:
Im image 6 , we find the lower bound of a number using Math object and floor method.
6.parseInt() and parseFloat()
preseInt and parseFloat both are functions and both take a string and return numbers. But on the other hand, parseInt() return an integer type of number and parseFloat return a Floating type of number, and if our string is simply text or number with text then it will show NaN(Not a Number)
The use-case of the parseInt and parseFloat is :
In this image, we declare a number as string in numberString and we console it and get output, 150. then we dealer floatingNumber variable and we parse the string in parseFloat function and we get the type using typeOf method and we see it is Number, That means it is a floating numbers. If er use parseInt then it will be an integer number.
7. push() , pop() , shift() , unshift() , The important array methods .
push()
push() method is a method , that add the called array in push(), Like push(10) , 10 will be added as last element of an array.
Here we see the output [1,2,3,4,5,6] , here we push 6 the number array as the last element. Then the number will be a new set of arrays with 6.
Similarly, if we want ton remove the last element of an array then we use pop()
If we want to add a number in first index we use unShift() like ,
and we remove the first element then we can use shift()
These methods are very important and most uses of an array in javascript.
8. Besic usage of filter() method.
Filter is simply filtering array method, that filtering array with its requirements [users sets that requirements ],
Here we declare an array of objects, they both have names and ages. If we want to decide, whose age is greater or equal 18, he can be going to cinema hall then we using the filter() method and find the person. Here Jamal and Kofil is going to cinema hall.
9. Usage of map()
Map is an array method that method we can manipulate with array and we can work with multiple elements at a time. the method creates a new array with the results of calling a function for every array element.
The map method calls the provided function once for each element in an array, in order.
map() doesn’t change the original array :
Here we see some names are declared in the name variable, and we declare a new const nameWithRank and we just take every element and added hossain, but it doesn’t change the original element of the array.
10. Reduce method in array.
Reduce is an important method in array , Reduce take to parameter as an input function and the first one is the previous and second one is current then we can make sum of all array numbers or concat if all string in the array.
Here the basic example of reduce:
We declare myTask array and in array, we have a list of string, if we want to combine all then normally it's not easy, but if we want to combine it using reduce() it will be more fruitful for us, here we take two-parameter, first one is for the previous and second one is current then return previous + return. And the first element, ‘Hi’ doesn't have any previous element so we use dependency after curly bracket as an empty string. If we work with numbers then we can put there simply 0.