10 JavaScript Methods That Every Developer Should Know.

Sadeka Ahmed
5 min readMay 15, 2021

--

Today we are going to learn some special topics of JavaScript. I will cover the topic of primitive values, block scope, cross browsing, and some ES6. So, let’s go….

1. Primitive Values:

In JavaScript, there are many primitive values like “String”, “Number”, “Null”, “undefined”, “Boolean” etc. Which are not manipulated by us like any Object or Function.

At first, you may think what is difference between number & object!!! because call and store value what we need in there. But wait, there is something special for you 😉

primitive values examples:

look at this example, there are 2 variables x, y. I assign x into y and console.log() you see there is nothing special, After assigning y in a new value that is the same thing before we get.

reference values:

OMG! why x values get changed? Yes, That is the main point, primitive values are just what we use, not manipulate like objects. In Object, they pass their reference not their values that’s why addOne function changes the main reference where store same object x.

2.indexOf():

The indexOf() method is used to get the index of the first occurrence of specified characters in a string. The search will start from the beginning of the string. Its default index is 0. If the value is not found, it returns -1. The indexOf() method is case sensitive. The following example uses the indexOf().

3. trim():

The trim() is a method that is used to removes whitespace from both the start side and end side of a string. The trim method doesn’t change the original string. I have to create an instance of the trim() method.

4. Block Scope:

If/else or any Loops where you write functionality inside {}, then it’s to be considered a block scope. let & const keyword is fully dependent in a block scope, its attitude into a block scope one thing and outside another thing.

you can’t access any block element outside(global) the block, but you can access anything into the block scope from outside(global).

Look you get an error to access data in global scope, which is inside block scope.

5. isNaN() Method:

isNaN() Method returns true if the argument is NaN, Otherwise it returns false.

6.Cross Browsing :

Out of all major web technologies, there is no other technology as vilified for cross-browser compatibility as JavaScript. Despite the advancements in pure HTML and CSS, it’s true that you cannot easily build web apps or websites without it.

7. Spread Operator:

It’s come same as the arrow function in es6. In the modern JavaScript framework, there is a need to include all array elements in the new array. In this case, you need to Loop through the array to push all elements into the new array. So, this problem fixed our spread operator. Its syntax looks like […oldArray].

8. ceil():

The ceil() method is used to return the smallest integer value that is greater than or equal to a number. In other words, the ceil() method rounds a number upward and returns an integer value. If the passed argument is already an integer, the value will be the same as the passed argument. Let’s see some examples:

9. Arrow Function:

Arrow functions come in the es6 version in JavaScript. It’s easy to call a function & some efficient features. It can call one line only , multiple lines what you need. But the main thing is Arrow function has no name, so you need to call it like function expression.

In the example, there are 2 types to call arrow function. First, you need to pass the parameter then you need to write the “=>” arrow symbol then you write your functionality & last you need to return it. Second, if you write it one line you don’t need to return, but if you use {} then you need to write return.

10. map():

map is one of the common method you need to use. It works for array and alternative for loops. When use map in the array it will return the same copy of the main array. map iterate all elements of the array one by one, so you can do something like loops when it iterates one by one.

map returns all square root in numbers elements

--

--