5 Concepts You Should Know about JavaScript

Swati Jaiswal
2 min readNov 25, 2020

JavaScript becomes the world’s most popular programming language now a days it is playing a huge role not only for developing client site(frontend) programing even in server side (backend) , here few terminologies which we should know as a developer .

First Class function :-
A programming language is said to have First-class functions when functions in that language are treated like any other variable. For example, in such a language, a function can be passed as an argument to other functions, can be returned by another function and can be assigned as a value to a variable.

Example -

Assign a function to a variable :

const test = function() {
console.log("foobar");
}
// Invoke it using the variable
test();

Pass a function as an Argument: -

const sayHello = function() {
return function() {
console.log("Hello!");
}
}
const myFunc = sayHello();
myFunc();

Return a function:-

function sayHello() {
return function() {
console.log("Hello!");
}
}

Anonymous Function:-
An anonymous function is a function that was declared without any named identifier to refer to it. As such, an anonymous function is usually not accessible after its initial creation.

Example: -

let show = function () {
console.log(‘Anonymous function’);
};
show();

Callback Function:-A callback function is a function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action.

Example-

function greeting(name) {
alert('Hello ' + name);
}

function processUserInput(callback) {
var name = prompt('Please enter your name.');
callback(name);
}

processUserInput(greeting);

Higher-Order Function:-
Higher order functions are functions that operate on other functions, either by taking them as arguments or by returning them. In simple words, A Higher-Order function is a function that receives a function as an argument or returns the function as output.

Example: -

const persons = [
{ name: 'Peter', age: 16 },
{ name: 'Mark', age: 18 },
{ name: 'John', age: 27 },
{ name: 'Jane', age: 14 },
{ name: 'Tony', age: 24},
];
const fullAge = persons.filter(person => person.age >= 18);
console.log(fullAge);

Pure Function:-
A function is only pure if, given the same input, it will always produce the same output. You may remember this rule from algebra class: the same input values will always map to the same output value. However, many input values may map to the same output value.

Example:-

function getSquare(x) {
return x * x;
}

I hope it will help you while going for interview If you liked this article, hit that clap button below 👏. and share so others can find it as well !, Also feel free to leave a comment below.

Thanks for reading………

for further readings-

--

--