Some Javascript Concepts

Muhammad Rifat
4 min readMay 5, 2021

Learn about Javascript

Anonymous Function:

A function without a name is called an anonymous function.
Example:

Closures:

Creating a closed environment by calling another function within a function is called closure. Like Restaurant Kitchen.
Example:

In this code example, kitchen() function returns another anonymous function. This anonymous function returns 1 egg per call. Then below two servePlate are a call to kitchen() for the egg. servePlate1 calls three times for egg, so it gets 3 eggs, and serverPlate2 calls two times for egg, so it gets 2 eggs.

After understanding the above example, we can see that, There is a different closed environment in servePlate1 and servePlate2.

Javascript String Method:

charAt():
-is a string method that returns a character at the specified index of a string.
Syntax: string.charAt(index)
Example:

In this code example, the output shows v for index 3. (Index of the first character of a string is 0)

concat():
-is a string method that concatenates multiple strings and returns a new string.
Syntax: string1.concat(string2, string3, …., stringN)
Example:

includes():
-is a string method for finding any character or character set that returns true or false as appropriate.
Syntax: string.includes(searchValue)
Example:

In this code example, when searching ‘hello’, it returns false, because this method performs to search in case sensitive.

endsWith():
-is a string method for finding out a string ends with the characters of a specified string that return true or false as appropriate. This method performs to find out in case sensitive.
Syntax: string.endsWith(searchValue); string.endsWith(searchValue, length);
Example:

lastIndexOf():
-is a string method that returns the position of the last search value of a specified search value in a string. If don’t match, it returns -1. This method performs in case sensitive.
Syntax: string.lastIndexOf(searchValue)
Example:

split():
-is a string method that is used to split a string with a specified substring and it returns a new array.
Syntax: string.split(seperator substring, limit)
Example:

trim():
-is a string method that removes whitespace from both sides of a string. It mostly used for validating data of form.
Syntax: string.trim()
Example:

Javascript Number

isNaN():
-is a function that checks a value is a legal number or not. NaN means Not a Number. if the input value is numeric, then this function returns false. and if the input value is not numeric, then this function returns true.
Syntax: isNaN(value)
Example:

parseInt():
-is a function that converts a string to an integer.
If the string starts with “0x”, this function returns decimal from hexadecimal.
Otherwise, this function returns a decimal value.
Syntax: parseInt(string)
Example:

Javascript Array

filter():
-is a method that executes on an array for various perspectives and returns a new array.
It does not change the original array.
Example:

map():
-is a method that executes each element of an array. It does not change the original array and returns a new array.
Syntax: array.map(function(element, index, array), this element)
Example:

reduce():
-is a method that reduces the array to a single value. It executes for each element of an array. It contains an anonymous function and returns the value of this function is stored in a variable (total). It does not change the original array.
Example:

--

--

Muhammad Rifat

I'm a developer with a vast array of knowledge in many different front-end and back-end languages, responsive frameworks, databases, and best code practices.