JavaScript Day 16 — Mastering JavaScript Basics: A Comprehensive Guide for Interview Preparation
100 Days of JavaScript Interview Prep: A Beginner’s Journey


Welcome to Day 16–100 Days of JavaScript Interview Prep: A Beginner’s Journey
Embarking on a 100-day adventure focused on learning, practice, and growth sounds like an incredibly rewarding journey.
DAY 16 (April 7th, 2024) — Core Functions Interview Question JavaScript with example?
Question 1 : What do you understand by Higher order function ?
Answer :
A higher-order function is a concept in functional programming where functions can take other functions as arguments and/or return functions as their results.
In other words, a higher-order function either takes one or more functions as arguments, returns a function, or both.
Higher-order functions are a powerful feature of functional programming.
Advantages
- It makes code concise, flexible, and modular code.
2. It allows abstraction of common patterns and behaviors,
3. It allows promoting code reusability and maintainability.
function applyOperation(operation, a, b) { // example of high order function
return operation(a, b);
}
function add(x, y) { // Define a function to add two numbers
return x + y;
}
// Pass the 'add' function as an argument to 'applyOperation'
console.log(applyOperation(add, 3, 4));
// Output: 7applyOperation is also a higher-order function because it takes the add function as an argument.

Question 2 —Explain calling a function/functions in JavaScript with example?
Answer :
Most people confuse with defining a function or executing a function. Both has different meaning and purpose.
Let’s first understand, defining a function does not mean execute it.
Calling a function/functions refers to the act of invoking or executing a function.
- Function Invocation:
Means process of calling the function by its name, followed by parentheses ().
For example- myCard().
2. Passing Arguments:
If we need to pass any input values, we need to pass as arguments when calling function
myCard(name, email)
3. Execution:
When we call a function, then program execute the code inside the function.
function myCard(name, email){
this.name = name ;
this.email = email ;
return this.email;
}4. Return Value:
After executing the code inside the function, the function may optionally return a value.
function myCard(name, email){
this.name = name ;
this.email = email ;
return this.email;
}
console.log(myCard('kk','kk@test'))
// Define a function that takes two numbers as arguments
function addTwoNumber(a, b) {
return a + b; // // and returns their sum
}
const sum = addTwoNumber(3, 4);
console.log(sum);
// Output: 7
In this example,
Step 1 —
add(3, 4)is the function call
Step 2 — It invokes the
addfunction with arguments3and4.
Step 3 — The function adds these two numbers together and returns the result, which is then stored in the variable
result.
Step 4 -Finally, the value of
resultis printed to the console.
Question 3 — What do you understand by argument and parameter in JavaScript with example ?
Answer -
In JavaScript, “parameters” and “arguments” are similar concepts that are used interchangeably, but they have different meanings in the context of functions.
Parameters:
Parameters are defined in the function signature within the parentheses ().
function getName(name) {
console.log('Hello, ' + name + '!');
}In this example, name is a parameter of the greet function.
Arguments :
- Arguments are the actual values that are passed to a function when it is called.
getName('tommy');
Happy Coding and Stay Tuned :)
Kind is cool !!!
Share knowledge to gain knowledge !!!!
Be kind and treat people with respect !!
If you find my videos helpful, then please subscribe, Claps and follow to support :)
Cheers Kirti Kaushal

#Coding #interview #javascript #Mastering JavaScript100days





