10 javaScript Things that every developer should know

Fardin Khan
4 min readMay 5, 2021

Brandon Each created javascript at 1995. He was about to named it Livescript but for a wise marketing move they named it javascript because that time java was really very popular.
after that javascript officially follow echmascript standard. The standard recived a important update at 1999 in echma script 3.
after that ECMAscript 5 published in 2009. but that’s not a major. The biggest update what take js to a whole other level is 6th update in 2015. We call it ECMAscript 6 or ES6.

Today we will talk about different javascript topics let’s start with

Let’s start with one kind of javascript string

1 charAt()
It’s used for finding the character using the index number.

Example :

const name = ‘Fardin Khan’ ;

console.log(name.charAt(2))

Here output will be r because our index number start with 0 and get incremented.

#charAt() used for finding the character according to index number left from right

2. concat()

It’s basically work like + oparetor

When you use + between 2 string they got into one concat() is just similar as that.

It mixed the two string let’s understand with a example

const fName = ‘Fardin’;

const lName = ‘Khan’ ;

const output = fName.concat(“ “, lName)

Output will be : Fardin Khan

See It’s just similar like this

var output = fName + lName ;

Output will be same

3. indexOf()

indexOf() method used for finding a strings index number.

It’s work like this

string.indexOf(‘Exact string you wanted to find the index number’)

Example :

const favouriteFoods = ‘kabab,biriyani,meat,burger,pizza,ice-cream,chocolate’;

const result = favouriteFoods.indexOf(‘kabab’);

Expected result is 0.

Here’s the kabab starts at the very begging so It’s index number is 0 and with indexOf you can find that

If it don’t find anything according to your input it will just return -1

4. Slice

It’s kinda favourite of mine. Today we will just discuss about it with stings but it’s mostly use with array.

Okay I think you already experienced how we slice our food or cake sometime. It’s exactly like that. There’s a starting point and a end point and between these 2 point the middle part will be sliced

Syntex of slice ()

slice (beginIndex)
slice (beginIndex,endIndex)

Slice extract the sellected text from your input and make a new string and show that in output.

Let’s understand with a example

var life = ‘no pain no gain’;

console.log(life.slice(7))
console.log(life.slice(7,9))

In first case it will slice from the no which is at the index position 7 to the end
So out put will be : no gain

But in 2nd case we defined the start as well as end point so output will be : no

You can use slice using negative index then it will just count index number from right to left instead of left to right .
Try yourself this code you will understand

var life = ‘no pain no gain’;

console.log(life.slice(-7))

5.isNaN()

It’s under javascript numbers

isNaN() is a method where it will return a boolean according to your input

Your input should be NaN and type should be Number then only it will show true

Example :

var num1 = NaN;

var num2 = 2 ;

var num3 = ‘NaN’ ;

console.log(num1.isNaN(),num2.isNaN(),num3.isNaN());

Here only num1 output will be true and the other will be false.

6. Math.ceil()

It’s a function where always it rounds up a number to the next intiger

Like if you give it 12.5 or 12.2 it will round it up to 13

Example

var num = 12.5 ;

console.log(Math.ceil(num))

Output will be 13. So the ceil will like a big heart person who will always give you more.

7.Math.round()

Math.round() function will rounds up a value to the nearest intiger

If you give 12.3 then it will round up into 11 but if you give more than 12.5 like 12.53 or 12.7 it will return 13

8.Array.filter()

Okay now we will be discussing about filter option of array in js.

The filter() method basically run a test according to given condition and make a new array with the passed values.

Example

const mbCompany = [ “apple”,” samsung”,”redmi”,”realme”,”vivo”]

const res = mbCompany.filter(mb => mb.length > 4);
console.log (res);

Here you will see the mobile companies name more than 4 character will be sellected and it will create a new array with it. Filter work in this way that it will take each one item from a array then cheack it with the condition given and if it’s true then it will add that value to the new array and after checking all the values like a loop it will return a new array.

9.Array.forEach()

forEach() method actually take the elements of an array one by one and does the work given by coder.

example :

const friends =[riyad,mahin,maruf,bob,labib]

friends.forEach(friend => console.log(friend))

now here it will print all the elements of friends array one by one. This is how for each works kind of for loop.

10.Array.splice()

Here's it's the opposite of slice. Here you give the start count and end count and it will remove the selected part and return the rest as a new array

--

--