JavaScript Blogs

String, Number, Math, Array

Javascript Blogs
  1. charAt()

charAt() is a method. It is a find out a character at a specific index in a string and access an individual character in a string. The index of the first character is 0, the second character is 1, and so on.

Syntax : “string”.charAt(index)

// expected output: “index number character”

Example :

return "moshiur".chartAt(1) 
//returns "o"

2.concat()

The concat() method is used to join two or more strings. This method does not change the existing strings, but returns a new string.

Syntax : “string1”.concat(‘ ’, string2)

// expected output: “string1 string2”

Example :

let firstName = "Moshiur";
let lastName = "Rahman";
return (firstName.concat(' ', lastName))
//output "Moshiur Rahman"

3.toLowerCase()

The toLowerCase() method returns the value of the string converted to lower case. In other words, it converts all characters of the string into lower case letter.

Syntax : “STRING”.toLowerCase()

// expected output: “string”

Example :

let name = "MOSHIUR"
return name.toLowerCase()
//output "moshiur"

4.toUpperCase()

The toUpperCase() method returns the value of the string converted to uppercase.In other words, it converts all characters of the string into upper case letter.

Syntax : “string”.toUpparCase()

// expected output: “STRING”

Example :

let name = "moshiur"
return name.toLowerCase()
//output "MOSHIUR"

5.isNaN()

Number.isNan() does not convert the values to a Number, and will not return true for any value that is not of the type Number.

Syntax : Number.isNaN(value)

Example :

Number.isNaN(NaN) //true
Number.isNaN(0 / 0) //true
Number.isNaN(111) //false
Number.isNaN(-1.11) //false
Number.isNaN(9-2) //false
Number.isNaN(0) //false
Number.isNaN('111') //false
Number.isNaN('String') //false
Number.isNaN('') //false
Number.isNaN(true) //false
Number.isNaN(undefined) //false
Number.isNaN('NaN') //false

6.parseFloat()

The parseFloat() function is used to accept the string and convert it into a floating-point number. If the string does not contain a numeral value or If the first character of the string is not a Number then it returns NaN.

Syntax : parseFloat(string)

Example :

let n = parseFloat("2021.235");
//Output: n=2021.235 (floating point Number)

7.parseInt()

The parseInt() method parses a string argument and returns an integer of the specified radix or base.

Syntax : parseInr(string)

Example :

let n = parseInt("2021.235");
//Output: n=2021(Number)

8.Math.abs()

The Math.abs() method is used to return the absolute value of a number. It takes a number as its parameter and returns its absolute value.

Syntax : Math.abs(value)

Example :

Math.abs(-1)
Output : 1;
Math.abs(0)
Output : 0;

9.Math.ceil()

The Math.ceil() function in JavaScript is used to round the number passed as parameter to its nearest integer in Upward direction of rounding i.e towards the greater value.

Syntax : Math.ceil(value)

Example :

Input  : Math.ceil(6.23)
Output : 7

Input : Math.ceil(0.7)
Output : 1

10.arr.findIndex()

The arr.findIndex() method used to return the index of the first element in a given array that satisfies the provided testing function.

Syntax : array.findIndex(function(currentValue, index, arr), thisValue)

Example :

function isOdd(element, index, array) {
return (element%2 == 1);
}

console.log([4, 6, 8, 12].findIndex(isOdd));
Output : -1

11.array.forEach()

The array.forEach() method calls the provided function once for each element of the array. The provided function may perform any kind of operation on the elements of the given array.

Syntax : array.forEach(callback(element, index, arr), thisValue)

Example :

const array1 = ['Moshiur', 'Rahman', 'Ifad'];array1.forEach(element => console.log(element));//output : 
"Moshiur"
"Rahman"
"Ifad"

Web Developer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store