Array And Function - Study Mode

[#21] Consider the following code snippet function printprops ( o ) { for(var p in o ) console . log ( p + ": " + o [ p ] + "n" )

} What will the above code snippet result ?
Correct Answer

(B) Returns undefined

Explanation

Solution: The above code snippet returns undefined.

[#22] Consider the following code snippet function hypotenuse ( a, b ) { function square ( x ) { return x * x

} return Math . sqrt ( square ( a ) + square ( b ))

} What does the above code result?
Correct Answer

(A) Sum of square of a and b

Explanation

Solution: The above code snippet contains nested function in which the function hypotenuse(a,b) has another function inside its scope, function square(x). The interesting thing about nested functions is their variable scoping rules. They can acceess the parameters and variables of the function (or functions) they are nested within.

[#23] 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?
Correct Answer

(C) var strict = (function() { return !this }())

Explanation

Solution: The above code defines and invokes a function to determine if we’re in strict mode.

[#24] Which is an equivalent code to invoke a function m of class o that expects two arguments x and y?
Correct Answer

(D) o.m(x,y)

Explanation

Solution: The code above is an invocation expression: it includes a function expression o.m and two argument expressions, x and y.

[#25] Consider the following code snippet : var grand_Total =eval (" 10*10+5 ")

The output for the above statement would be :
Correct Answer

(C) 105 as an integer value

Explanation

Solution: Even if the string value passed as a parameter to eval does represent a numeric value the use of eval() results in an error being generated.