Easy way to learn Javascript
JavaScript is a programming language that use to create dynamic web pages. It is lightweight and most commonly used as a part of web pages. Basically, javascript is more popular for its simplicity and powerful skills.
Types of Javascript
1. Number.NaN
It represents Not A Number. It can be used to find whether a value is a number or not. Let’s see an example to make it more clear:
const isNumber =(a)=> {
if (isNaN(a)) {
return Number.NaN;
}
return a;
}
2. Number.parseFloat()
In this method, we can parse an argument and get a floating-point number. If a number can’t be parsed then it will return NaN.
Input:
const num1 = parseFloat("10.15");
const num2 = parseFloat("hello world");console.log(num1);
console.log(num2);Output:
10.15
NaN
3. Number.parseInt()
This method parses an argument and gets an integer-point number. If a number can’t be parsed then it will return NaN.
Input:
const num1 = parseInt("10.15");
const num2 = parseInt("hello world");console.log(num1);
console.log(num2);Output:
10
NaN
4. String.prototype.charAt()
charAt() method returns a specific index of character in a string.
Input:
const myFunction = () =>{
const str = "HELLO WORLD";
const result1 = str.charAt(0);
const result2 = str.charAt(4);
console.log(result1);
console.log(result2);
}
myFunction();Output:
H
O
5. String.prototype.concat()
concat() method joins two or more strings and returns a new string.
Input:
const myFunction = () =>{
const str1 = "HELLO ";
const str2 ="WORLD";
const result = str1.concat(str2);
console.log(result);
}
myFunction();Output:
HELLO WORLD
6. String.prototype.indexOf()
indexOf() method returns the index of the first occurrence of a specified value in a string. From the search, if it can’t find any value then return -1.
Input:
const myFunction = () =>{
const str = "Javascript is a programming language";
const result = str.indexOf("programming");
console.log(result);
}
myFunction();Output:
16
7. String.prototype.replace()
replace() method search a string and replace it with a specific string and returns a new string.
Input:
const myFunction = () =>{
const str = "Javascript is a programming language.";
const result = str.replace("Javascript","Python");
console.log(result);
}
myFunction();Output:
Python is a programming language.
8. Array.prototype.concat()
concat() method join or merge two or more array and return a new array.
Input:
const myFunction = () =>{
const list1= [Sabbir, Asif, Herry ];
const list2= [Sajib, Pallab, Shuvro];
const result = list1.concat(list2);
console.log(result);
}
myFunction();Output:
[Sabbir, Asif, Herry, Sajib, Pallab, Shuvro]
9. Array.prototype.find()
find() method returns the first value of an array element that satisfied a given condition.
Input:const friendsAge = [10,14,17,22,35,40];
const myFunction = () =>{
const result= friendsAge.find(age => age > 15);
console.log(result);
}
myFunction();Output:
17
10. Array.prototype.map()
map() method calls every element of an array and returns a new array. This method will not execute if there is no value in the array.
Input:const values= [5, 10, 15, 30, 50];
const myFunction = () =>{
const result= values.map(value => value + 10);
console.log(result);
}
myFunction();Output:
[15, 20, 25, 40, 60]