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

Welcome to Day 12–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 12 (April 3rd, 2024) —Continuing Function in JavaScript with examples
Question 1 — What is an Anonymous function?
Answer — Anonymous functions, also known as lambda functions or function literals, are functions that are defined without a name.
An anonymous function may also be used as a parameter for another function.
A function doesn’t need to be referenced by name
//Using an normal anonymous function without name
const myName = function(){
return 'kk';
}
//Using an anonymous arrow function
const myName2 = () =>{
return 'test 2';
}
//Using an anonymous function as a callback
setTimeout(function() {
console.log("This is an anonymous function.");
}, 300);
Question 2 — Write a JavaScript function that takes an array of numbers and returns a new array where each number is doubled.
Note — use an anonymous function inside the function to perform the doubling.
Answer :
function doubleArray(numbers) {
return numbers.map(function(num) {
return num * 2;
});
}
// Test the function
const numbers = [1, 2, 3, 4, 5];
const doubledNumbers = doubleArray(numbers);
console.log(doubledNumbers); // Output: [2, 4, 6, 8, 10]
Question 3—What is a Function Statement ?
Answer:
In programming languages like JavaScript, Python, and others, a function statement or function declaration is a way to define a named function.
So both are same (function statement and function declaration)
// Function declaration or function statement
function add(a, b) {
return a + b;
}
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

Other Articles
#Codinginterview #interview #javascript #javasscriptInterview #coding





