Valid JS-Dev-101 Dumps shared by EduDump.com for Helping Passing JS-Dev-101 Exam! EduDump.com now offer the newest JS-Dev-101 exam dumps, the EduDump.com JS-Dev-101 exam questions have been updated and answers have been corrected get the newest EduDump.com JS-Dev-101 dumps with Test Engine here:
A developer writes the code below to return a message to a user attempting to register a new username. If the username is available, a variable named msg is declared and assigned a value on line 03. function getAvailabilityMessage(item) { if (getAvailability(item)) { var msg = "Username available"; return msg; } }
Correct Answer: C
The correct answer is C. When getAvailability(item) returns true, the code inside the if block executes: var msg = "Username available"; return msg; The variable msg receives the string value: "Username available" Then that same value is returned from the function. The key point is that var is function-scoped, not block-scoped. So msg belongs to the function scope of getAvailabilityMessage(). However, because the return msg; statement is inside the same if block, the function immediately returns the assigned string when the username is available. Option A is incorrect because msg is defined before it is returned. Option B is incorrect because "newUserName" is not assigned or returned anywhere in the function. Option D would only happen if getAvailability(item) returned false, because then the function would finish without an explicit return value. For the available username scenario, the verified answer is C.