10 Common JavaScript Method You Need to Know

You know that javascript is the most confusing programming language so today I am going to talk about 10 common javascript methods that can confuse you from time to time. Check it below

  1. chaAt:

charAt is the pre-define function of javascript when you try to find a specific character from a string, the chaAt function will find it by giving it index value. One thing you should keep in mind is that indexing in javascript starts at zero.

const speech = ‘Dhaka is the capital of Bangladesh’

const index = 6

console.log(`the character at index ${index} is ${speech.charAt(index)}`)

The output is ‘the character at index 6 is i’

2. concat:

The short version of concatenating is concat which means to connect two or more strings. When you combine any two or more strings together, you have to remember you must enter the second string within the parameters of the Concat function. There have no hard and fast

rules, if you want you can use the last string at the first.

const firstName = ‘Ringku’

const lastName = ‘Rahman’

console.log(firstName.concat(‘ ‘, lastName))

The output is ‘Ringku Rahman’

3. includes:

If you want to find a word or character in a string, you must use the includes method. This will give you a value return on either true or false. For example

const sentence = ‘My name is Ringku Rahman’

const character = ‘i’

console.log(`the character ‘${character}’ ${sentence.includes(character) ? ‘is’ : ‘is not’} in the sentence`)

The output is ‘the word ‘is’ is in the sentence’

4. parseFloat:

If you want to get a decimal fraction of a result, you must use the parseFloat function. if two of your input are fraction then you can pass them into the argument. otherwise, you can pass the input that contains the fraction into the argument. However,

it is better to pass both the fraction into the argument for the safe side. Here is an example:

let num1 = 10

let num2 = 15.2

// const result = parseFloat(num1 + num2)

const result = num1 + parseFloat(num2)


The output is ‘25.2’

5. parseInt:

If you want to get the integer value of a result, you must use the parseInt function. Many times we want to get integers in our calculations, then this function helps us to get a integer value. You can see below example

let num1 = 10.5

let num2 = 15

const result = num2 + parseInt(num1)

// const result = parseInt(num1 + num2)


The Output is ‘25’

6. Abs:

abs usually distinguish between two numbers. A lot of times we want to get the difference between two numbers, how much is bigger it is or how much is smaller it is, we can determine that with math.abs

let a = 50

let b = 30

// const result = Math.abs(a — b)

const result = Math.abs(b — a)


The output is ‘20’

7. ceil:

Ceil usually means to pull something up and round it. A lot of times we want to get a fraction as we want to round it up. If a fraction is greater than .50 or up to .50 but it is not an integer then the Math.ceil method convert the number to a whole number + 1 for example:

let num1 = 55.51

let num2 = 44

const result = Math.ceil(num1) + num2


The output is ‘100’

8. floor:

floor is commonly used in JavaScript to convert a fraction below .50 to a integer value. So any fraction point is .49 but not .50 then Math.floor method convert the number to a whole number -fraction. For example:

let num1 = 55.49

let num2 = 45

const result = Math.floor(num1) + num2


The Output is ‘100’

9. min:

By min, we usually mean the minimum value of something. You may often have to work with javascript arrays to find the minimum value of an object then using the Math.min method, it is very easy to find the smallest object of an array. Here is an example:

const KamalMoney = 5000

const JamalMoney = 7000

const RedoyMoney = 12000

const result = Math.min(KamalMoney, JamalMoney, RedoyMoney)


// Output is ‘5000’

const numArray = [5, 77, 66, 85, 41, 65, 1, 61, 18]

const Output = Math.min(…numArray)


// Output is ‘1’

10. max:

Again, in the case of Max, we understand that the maximum value of something. Math.max is used to find the largest object in an array.

Here is the example:

const numArray = [5, 77, 66, 85, 41, 65, 1, 61, 18]

const Output = Math.min(…numArray)


// Output is ‘85’

Self-taught frontend developer