const name = “sama”;
const index = 3;
//expected value ‘a’
2.concat():The concat() method concatenates two different string into a new one.It took one or more strings as argument and returns a new string.it does not change or effect the original string.it just concates the string.if the passed arguments are not the string type concat() method convert them into string type and concates them.
Syntax:concat(str) or concat(str1,str2)
const firstName = “khadiza”;
const lastName = “sama”
//expected output khadiza sama
3.slice():slice() method took a portion of string and return it into new string.it does not change or affect the original string.it take two parameter as argument.one is the begin index and other is end index.the end index is optional.if the parameter is negative the position is counted from the end of the string.
Syntax:slice(begin index,end index)
const name = “khadiza morioum sama”
const newName = name.slice(8,-4)
//expected output morioum
1.isNAN():isNAN() method is used to determine whether a value is not a number or not. it returns true or false as output. if the given value is NAN this function returns true otherwise false. the isNAN() function converts the tested value to a number, then tests it.
2.parseFloat():parseFloat() is a method that parses string from an argument and returns it in a floating number. it took string as a parameter.if the number cannot be converted it returns a NAN.
//expected value 45
3.parseInt():parseInt() is a method that parses a string from an argument and returns it in a whole number. spaces are allowed but only the first number is returned.it took string as a parameter. if the argument is not a string then it can be converted into a string using tostring() method. if the number cannot be converted it returns a NAN.
//expected value 50
MATH: It allows users to perform mathematical operations on numbers. it's not a functional object. it's not also a constructor type.it works with numbers. the are some methods of math. some of them are given below:
1.Math.abs():the abs() method returns a absolute value of a number.it does not matter if the passed value inside the abs() method is negative or positive.it always returns the absolute value. if the passed value is null then it returns NAN.
//expected value 9
//expected value NAN
2.Math.ceil():this function always returns a value that is rounded up to its nearest largest integer.if the passed value is null then I return 0.it does not give NAN error.
//expected value 6
3.Math.round():this function take a floating point number as parameter and return it as nearest integer.round() is a static method of math.
//expected value 6
4.Math.min(): this method returns the number with the lowest value. this is a static method. this takes numbers as parameters. if the parameter is not a number it converted it into a number but if it cant be converted then this method returns NAN.
const a=4 ;
const b= 7;
const c = Math.min(a,b);
//expected value of c is 4;
Hope you have enjoyed reading this article and found this article helpful.if you have enjoyed this then follow me on LinkedIn.