11.Can you assign a anonymous function to a variable?
Yes! An anonymous function can be assigned to a variable.
12.Can you pass a anonymous function as an argument to another function?
Yes! An anonymous function can be passed as an argument to another function.
13.What is arguments object in JavaScript?
JavaScript variable arguments represents the arguments passed to a function.
14.How can you get the type of arguments passed to a function?
Using typeof operator, we can get the type of arguments passed to a function. For example −
function func(x){
console.log(typeof x, arguments.length);
}
func(); //==> “undefined”, 0
func(1); //==> “number”, 1
func(“1”, “2”, “3”); //==> “string”, 3
15.How can you get the total number of arguments passed to a function?
Using arguments.length property, we can get the total number of arguments passed to a function. For example −
function func(x){
console.log(typeof x, arguments.length);
}
func(); //==> “undefined”, 0
func(1); //==> “number”, 1
func(“1”, “2”, “3”); //==> “string”, 3
16.How can you get the reference of a caller function inside a function?
The arguments object has a callee property, which refers to the function you’re inside of. For example −
function func() {
return arguments.callee;
}
func(); // ==> func
17.What is the purpose of ‘this’ operator in JavaScript?
JavaScript famous keyword this always refers to the current context.
18.What are the valid scopes of a variable in JavaScript?
The scope of a variable is the region of your program in which it is defined. JavaScript variable will have only two scopes.
Global Variables − A global variable has global scope which means it is visible everywhere in your JavaScript code.
Local Variables − A local variable will be visible only within a function where it is defined. Function parameters are always local to that function.
19.Which type of variable among global and local, takes precedence over other if names are same?
A local variable takes precedence over a global variable with the same name.
20.What is callback?
A callback is a plain JavaScript function passed to some method as an argument or option. Some callbacks are just events, called to give the user a chance to react when a certain state is triggered.