Some important JavaScript core concepts that we use………
.toLowerCase()
This is a method that is use to make a string value to all lower case item..
whether it would lowercase or uppercase
Example :
const speech=“This is a book”
console.log(speech.toLowerCase());
Output: “this is a book”
.toUpperCase()
This is a method that is use for turn all the string to uppercase ,reither it is uppercase or not
Example:
const speech=”This is a book”
console.log(speech.toUpperCase());
Output: “THIS IS A BOOK”
.trim()
This method removes the whitespaces from both sides of a string
Example:
const science=” I am Shuvo. “;
console log(science);
Output — — “ I am Shuvo “;
console.log(science.trim());
Output — — “I am Shuvo”
.endsWith()
This method check the character that ends with the same character of a string or not
Example:
const main1=”They are my friends”;
console.log(main1.endsWith(friends));
output :True
const main2=”These are my classmates”
console.log(main2.endsWith(“class”));
output :false
Math.abs()
This fuction return the absolute value of a number,like this
x if x>0
0 if x=0
-x if x<0
example 1:
function add(a,b){
return Math.abs(a+b);
}
console.log(add(3,5));
output — — 8
console.log(add(5,4));
output — — 9
example 2:
function minus(a,b){
return Math.abs(a-b);
}
console.log(minus(3,5));
output: -2
console.log(minus(5,3));
output : -2
Math.floor()
This function return the biggest integar less than or equal to a given number
example:
console.log(Math.floor(6.98));
output — — 6
console.log(Math.floor(-6.98));
output: -7
Math.max()
The function returns the highest valued number passes into it
example:
console.log(Math.max(5,7,9))
output= 9
Math.min()
This function returns the lowest valued number …and if any parameter is not a number then it converted into one
example:
console.log(Math.min(5,7,9))
output= 5
Math.round()
This function returns the value of a number rounded to a nearest integer
example:
const one=1.5;
const two=2.7;
const total=Math.round(one+two);
console.log(total)
output — — 4
Array.concat()
This method is used to merge two or more arrays .in this method we can add two or more array together in a single array ..and we get a new array after merged these arrays
example:
const array1 = [‘shuvo’, ‘raihan’, ‘firoz’];
const array2 = [‘selim’, ‘Arif’, ‘Asif’];
const array3 = array1.concat(array2);
console.log(array3);
output — — [“shuvo”, “raihan”, “firoz”, “selim”, “Arif”, “Asif”]
Array.join()
This method is used for join an element in a single array …the element would be comma ,semi colon ,hyphen e.t.c … by using the join method ..we can make a new string by concatenating all of the element of an array
example:
const games = [‘football’, ‘cricket’, ‘baseball’];
console.log(games.join(‘-’));
output: “football-cricket-baseball”
Array.pop()
This method is used to remove the last item from an array and return it …
example:
const food = [‘burger’, ‘ice-cream’, ‘sweet’, ‘noodles’, ‘pizza’];
console.log(food.pop());
console.log(food);
output — —
>pizza”
> Array [“burger”, “ice-cream”, “sweet”, “noodles”]
Array.push()
This method is used for add an item to the end position of an array and return the whole array in to it.. and return the new length array
example:
const food = [‘burger’, ‘ice-cream’, ‘sweet’, ‘noodles’, ‘pizza’];
console.log(food.push(‘chanachur’));
console.log(food);
output — —
> 6
> Array [“burger”, “ice-cream”, “sweet”, “noodles”, “pizza”, “chanachur”]