Some Basic Concepts of JavaScript.

MH HABIB
3 min readMay 5, 2021

(1) About JavaScript:

JavaScript is a single-threaded, just in time compiled client-side dynamic language. But it can be used in the back end using the assistance of a run time environment node.js. JavaScript support prototype-based inheritance and multi-paradigm. It supports both functional as well as OOP programming features. Most of the syntax of JavaScript is based on java and c programming language.

(2) NaN:

NaN means Not a Number. It’s a special value. If the string is non-numeric then return NaN.

For example,

parseInt(‘world’, 10);

This function will return NaN because the string ‘word’ is not a number.

If we check the string ‘world’ using the isNaN() function then it will return true.

For example,

isNaN(‘world’);

Output: true. Because ‘world’ is not a number.

isNaN(‘1’);

Output: False. Because ‘world’ is not a number.

(3) parseFloat:

Number.parseFloat() is a JavaScript built-in method, it takes a value as an argument and parse it to a floating-point and returns a floating-point output excluding other characters. If the argument is not a number then it returns NaN.

For Enample,

function area(r) {

if (Number.isNaN(Number.parseFloat(r))) {

return 0;

}

return parseFloat(r) * 2.0 * Math.PI ;

}

console.log( area(‘4.567somechar’));

expected output: 28.695307297889173

Here arguments contain characters but it only parses only the numeric value and five a floating-point output.

(4) parseInt:

parseInt() is a JavaScript built-in method, it takes an argument and parse it to an integer number, and returns an integer number output excluding other characters and strings. If the argument is not a number then it returns NaN.

For example,

parseInt(‘’4somechar’’);

Its output will be only 4 and it will be number only, this method takes only the integer numbers and excludes other characters.

(5) Random:

Math.random() is a JavaScript built-in function. It can generate and return a pseudo-random floating-point number between the ranges of 0 to 1. It can be 0 but never be 1.

For example,

function getRandomNumber(x) {

var p Math.floor (Math.random() * x);

return p

}

console.log(getRandomNumber(3));

The out can be 0, 1 or 2

(6) indexOf:

indexOf() is a JavaScript array function, it usually used to find the index value of any character or string from the elements of an array.

For example,

var fruits = [‘banana’, ‘mango’, apple]

var position = fruits.indexOf(‘mango’);

console.log (position);

The output will be 1, which is the position of the string ‘mango’ inside the fruits array.

(7) filter:

filter() is a built-in function of JavaScript array, that creates a new array from the main array by checking the conditions inside the argument.

For example,

const names= [‘shayla’, ‘lipi’, ‘elie’, ‘rahat’, ‘rahman’, ‘parent’];

const output= names.filter(word => word.length > 5);

console.log(output);

expected output Array will be: [‘shayla’, ‘rahman’, ‘present’]

(8) find:

find() is a JavaScript array built-in function it is used to find the first element from an array on the basis of condition. There may be many values that can match the condition but this function only returns the first element from the array.

For example,

const setOffNumber = [5, 20, 12, 8, 13, 10, 144];

const output = setOffNumber.find(element => element > 12);

console.log(output);

The output will be 20, because, 20 is the first element that matches the condition. It is greater than 12.

(9) Push:

Push is another built-in array function of JavaScript. Push is used to add an element to the array. If it is necessary to add an element inside an array then we can use the push() function to add it. The element is passed using argument. And the element is added at the end of the array.

For example,

const fruits = [‘mango’, ‘apple’, ‘banana’];

const allFruits = fruits.push(‘orange’);

console.log(allFruits);

The output will be [‘mango’, ‘apple’, ‘banana’, ‘orange’]; ‘orange’ will be added on the last position of the main array.

(10)pop:

pop is another built-in array function of JavaScript. pop () is used to remove an element from the array. It is the opposite action of the push () function. If it is necessary to remove the last element, we can use the pop () function to remove it. The element is removed using argument. And the element is removed from the end of the array.

For example,

const fruits = [‘mango’, ‘apple’, ‘banana’];

const allFruits = fruits.pop();

console.log(allFruits);

The output will be [‘mango’, ‘apple’]; ‘banana’ will be removed from the last position of the main array.

--

--