10 Important things about JavaScript Part — 01

Masum Iraj
3 min readMay 5, 2021

--

Today I will go and discuss 10 important topics of JavaScript. I think you are excited. So, Let’s start without Wasting Time.

1.What is the Anonymous function?

A function that does not have a name is called the Anonymous function. Let’s take an example.

let myFun = function(x, y) {
return x + y;
};
console.log(myFun(3, 5)); // 8

2. Replace() function:

The replace method string with some or all matches pattern replace and return a new string.

const p = "The quick brown fox jumps over the lazy dog. If the dog reacted, was it really lazy?";console.log(p.replace("dog", "monkey"));// output: "The quick brown fox jumps over the lazy monkey. If the dog reacted, was it really lazy?"

3. Difference with double and triple equals:

Double equals (==) will show true if the operator’s value type is different and if the value is equal.

Triple equals operator (===) compare with value type and value but the results are always false. If you see the code, you will understand it better.

let a = "5", b = 5;console.log(a == b); // true
console.log(a === b); // false

4. Swapping by Temporary variable:

Let’s swap the values of variables a and b using a temporary variable Temp.

let x = 4, y = 2, swap;swap = x;
x = y;
y = swap;
console.log(x, y); // output: x = 2, y = 4

5. How to find the maximum and minimum value in an array:

Let’s see the example through the code.

const array = [34, 23, 32, 64, 84, 12, 42];console.log(Math.max(…array)); // 84
console.log(Math.min(…array)); // 12

6. Add an item to the beginning and ending an Array:

To add items to the beginning of an array, use the unshift method and To add items to the ending of an array, use the push method. Let’s take an example.

const array = [1, 2, 3, 4, 5];array.unshift(0);
console.log(array); // [ 0, 1, 2, 3, 4, 5 ]
array.push(6);
console.log(array); // [ 0, 1, 2, 3, 4, 5, 6 ]

7. Remove an item to the beginning and ending an Array:

To remove items to the beginning of an array, use the shift method and To remove items to the ending of an array, use the pop method. Let’s take an example.

const array = [1, 2, 3, 4, 5];array.shift();
console.log(array); // [ 2, 3, 4, 5 ]
array.pop();
console.log(array); // [ 2, 3, 4 ]

8. How to sort an Array:

Let’s see the example through the code.

const array = [21, 54, 24, 45, 95];array.sort();
console.log(array); // [ 21, 24, 45, 54, 95 ]

9. Concat() function:

This Concat() method used to bring two objects together and It returns a new Object.

let str1 = ‘Hello’, str2 = ‘ World!’;console.log(str1.concat(str2)); // Hello World!

10. Reverse() function:

The Reverse() method reverses an object. The first object element becomes the last and the last object element becomes the first.

const array = [1, 2, 3, 4, 5];console.log(array.reverse()); // [ 5, 4, 3, 2, 1 ]

--

--

Masum Iraj
Masum Iraj

Written by Masum Iraj

0 Followers

I am Web Developer.

No responses yet