JavaScript Functions
- What will happen if a return statement does not have an associated expression?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
A function without a return statement will return a default value. ifthe return statement does not have an associated expression then it returns an undefined value.
- A function with no return value is called
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
Void functions does not return a value. Functions with no return value are sometimes called procedures.
- Consider the following code snippet
function hypotenuse(p, q)
{
function square(n)
{
return n*n;
}
return Math.sqrt(square(p) + square(q));
}
What does the above code result?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
The above code snippet contains nested function in which the function hypotenuse(p,q) has another function inside its scope, function square(n). The interesting thing about nested functions is their variable scoping rules. They can access the parameters and variables of the function (or functions) they are nested within.
- Which of the following is the correct code for invoking a function without this keyword at all, and also too determine whether the strict mode is in effect?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
The above code defines and invokes a function to determine if we’re in strict mode.
- Which is an equivalent code to invoke a function fun of class opt that expects two arguments p and q?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
The two argument in a function are separated by a comma (,). The code above is an invocation expression: it includes a function expression opt.fun and two argument expressions, p and q.