JavaScript Core Concept 10 Important Topic I Learned

Mahmud Hasan
2 min readMay 5, 2021
  1. InnerFunction: The JavaScript function had a feature which is function declarations inside other functions. Also, nested functions in JavaScript are that they can access the variable in parent function scope. Nested functions can share variables in their parent function.
function name() {
var a = 4;

function name2() {
var b = 2; // name function can't use this
return a + b;
}
return name2(); // 5
}

2.Clousers: Clouser is nothing but inaction that is inner function can have access to the other function variables as well as the all global variables. And Also returned statement does not execute the inner function. The Function is executed only when followed by() , return statement, and returns the entire body of the function.

var a = 2;
const outerFunction = (a) => {
let b = 5;
const innerFunction = () => {
let sum = a + b + c;
console.log('the sum of two no. is ${sum}.'); // plz using backtick
}
return innerFunction;
}
let inner = outerFun(7);
console.dir(inner);
inner();
}
}

3. JavaScript(trim method):

The trim() method removes both sides of the string.

var string= "    Hello world";
document.write(string.trim());

4.JavaScript(substring method):

The substring() is similar to slice().The first argument indicates the index of the desire substring start. The optional argument indicates the index of the desired substring ends. The substring() cannot accept negative indexes.

var string= "Hello world this is an example of substring";
document.write(string.substring(4,15));
//15 not included

5.JavaScript Math method:

The Math object holds a set of const and methods that enable more complex math operations than the arithmetic operators. The Math object is static so its properties and methods accessed directly

Eample:

Math.PI(), Math.abs() , Math.round().Math.sqrt(),Math.floor() etc.

6.JavaScript(round method):

The round() method rounds a number to the nearest integer. As like 2.4 will be rounded down, 2.5 will be rounded up.

document.write(Math.round(4.1); //Ans is 4
document.write(Math.round(-8.6); //Ans is 8

7.JavaScript(Math.sqrt() method):

In this method to find the square root of a number in JavaScript,we can use the built in Math.sqrt() method.

var a = promt("Enter a number");
var b = Math.sqrt(a);

8.JavaScript Array:

Array is collection of data items and stored under a single name.We use array when we have to deal with multiple data items.Also, array are special type of objects.And JavaScript returns “object” for arrays.

var student = ["Rony" , "Jony"];
document.write(student);
document.write(typeof(student));

9.JavaScript (reduce() method):

The reduce () method executes a reducer function (we provide) on each element of the array, and result in a single output value. Also, reduce function takes four arguments which are: Accumulator, Current Value, Current Index, Source Array.

arr.reduce(callback(accmulator,
currentValue,[index[,array]])
[,initialValue])

10.JavaScript(splice() method):

The splice method changes the contents of an array by removing existing elements and add new elements. And this changes the main array.

var names =["Rony","Jony","Tony","Kony"];
names.splice(3);
document.write(names);

--

--