Some JavaScript Core Fundamental things

Md Khalid Hossain
3 min readMay 5, 2021

1. Some js number methods.

  • Number.isFinite() method checks that whether the passed value is an infinite number or not. for example :

console.log(Number.isFinite(1/0)); // output : false;

console/log(Number.isFinite(10/5)); // output : true;

console.log(Number.isFinite(0/1)) ; // output : false;

  • Number.isInteger() , determine the passed value is integer. example :

console.log(Number.isInteger(10)) // output : true => its an integer.

console.log(Number.isInteger(‘a’)) // output : false => cz ‘a’ is a string not integer.

  • Number.isNaN(), determine the passed is NaN and the types is number. example :

console.log(Number.isNaN()) // output : false => cz its not a NaN(Not a number)

  • Number.parseFloat(), its parse an argument and return back a floating point/ number with a fraction (1.22, 2.20, 5.00) and if the number can’t be parsed by argument, then it will be returned back NaN(Not a number)

2. js String and length, chartAt , and replace

Javascript string has many applicable methods. and they are really useful .but today I gonna write only three topics.

length, sometimes a developer need’s to check how much length (big)has in the array. for example :

const mySentence = “ hello, how are you?”; // now want check

console.log(mySentence.length) // output will be : 20

because “ hello, how are you?” in this line there have a total of 20 characters, and check that before hello there has space. so it's clear light count with space and whatever has.

  • string.charAt(), helps to access a specific value within a string.

const a= “hello”;

console.log(a.chartAt(5)) // output : ‘o’;

that's means which character's index number is 5 . so you calculate!

2.1 Using lastIndexOf()

Basically, this method returns the index within the calling String object of the last occurrence of the specified value.

Syntax of LastIndexOf():

lastIndexOf()

Example :

example explanation: first I have declared a variable with a paragraph, and second I have declared another variable call searchTerm. Now I want to know from the paragraph of the dog’s last index. follow the last line I have written inside a caret sign dynamically value of searchTerm. If you want you can change the value of searchTerm and try.

2.2 Using indexOf()

The indexOf() method returns the first index at which a given element can be found in the array, or -1 if it is not present.

indexOf()

--

--

Md Khalid Hossain

A learner, love to leran and share my programing knowledge.