CodingQuestions
CodingQuestions
Example17:
<script>
let func_one=param1=>param1;
let res=func_one("ReactJS");
document.write(res);
// /ReactJS
</script>
Example18:
<script>
let obj={
sub:``,
my_func:function(){
let inner_func=()=>{
this.sub=`ReactJS`;
}
inner_func();
}
};
obj.my_func();
document.write(obj.sub);
//Arrow functions ===> ReactJS
//Function expression ===> ""
</script>
Practice Paper
1) What is function?
Ans:
Ans:
43) function should accept one parameter i.e., number Return square of a
Number
44) function should accept one parameter i.e., number Return even / odd
45) function should accept one parameter i.e.; number Return prime number
or not
FAQ’S
1) Explain Functions in JavaScript?
✓ Particular business logic called as Function
✓ Functions are used to reuse business logic
✓ Types of functions
1)Function declaration / named functions
2)Function Expression / anonymous functions
3)Arrow Functions
2) what are the differences between function declaration and function
expression?
Function Declaration Function Expression
The function with particular name function without name called as
called as Function Declaration function expression
page. 119 https://www.excelr.com/
ExcelR Frontend by Samba
Syntax Syntax
Function Declaration Function Expression
function functionname (param1….) let variablename=function(param1,…) {
{ //business logic
//business logic }
} Function Calling
Function Calling variablename(arg1,…)
functionname(arg1,…)
let obj={
name: ‘ExcelR`,outer_func:
function () {
inner_func = () => {
document. write(this.name);
}
inner_func ();
}
};
obj. outer_func (); //ExcelR
4) Explain IIFE?
✓ IIFE stands for Immediately Invoked Function Expression
✓ IIFE is a JavaScript function that runs as soon as it is defined
Syntax:
(function () {
//business logic
})()
5) differences Between Spread Operator and Rest Parameter?
✓ Both Syntax’s are same (…)
✓ Spread Operator Expands an Array/Object into its Elements
Ex1.
let arr1= [10,20,30,40,50];
let [a, b, c, d, e] =arr1;
Ex2:
let obj= {key1: `ExcelR`, key2: `Technologies`};
let {key1, key2} =obj;
✓ Rest Syntax will take multiple elements and condenses into single
element
Ex1.
function func_one (…rest) {
document.write(rest);
}
func_one (10,20,30,40,50);
6) what is lexical scope?
✓ a variable defined outside a function can be accessible inside another
function defined after the variable declaration
✓ reverse not possible