HOTSPOT
You test a webpage that contains the following JavaScript code:
The webpage also contains the following markup:
You need to ascertain how the webpage responds when the user enters characters and then clicks
the add and divide buttons.
For each statement in the table, select Yes if the action causes the webpage to behave as described.
Select No if it does not. Make only one selection in each column.
Option a: the result will be 23. it concats two string “2” + “3”
Option b: the result is Infinity
Option c: unhandled exception
Yes i am agree with Wojita
So
YES
YES
NO
Is correct
Sorry
No
No
Yes
Just like Wojita said
https://jsfiddle.net/2y9cqzaw/2/
https://jsfiddle.net/safiya_iman/30L2sna4/
As the fiddle i tried, the answer should be
NO
YES
YES
correct me if my code is wrong.i have typed exactly the same thing which is in the Question.
I don’t know what’s going on, but I think that you are correct. In Fabian’s jsfiddle, functions are declared like ‘add = function()’ and in your jsfiddle – like ‘function add()’ which is exactly like in the question. And this two different approaches cause two different answers for the second question. In your jsfiddle there’s unhandled exception thrown, but in Fabian’s jsfiddle, there is Infinity. So I assume, that correct answer is No, Yes, Yes.
Ok, now I know – in stazy’s jsfiddle there is an exception for both actions – ‘add’ and ‘divide’, because javascript code from question doesn’t work on jsfiddle (it can’t find ‘add’ and ‘divide’ functions). So correct answer is No, No, Yes.
OK you’re a bit confused due to the wording of the question. First of all as you’ve seen jsfiddle runs your js code inside a function scope, so the functions add and divide are not available in the global scope as the question utilizes them, so @stazy has to rewrite them to be explicitly global functions.
Here’s a codepen that doesn’t screw up the code like that: https://codepen.io/anon/pen/gGWrYq
Secondly, the correct answers are: NO, YES, NO.
Option 1 is described by other comments.
Option 2 is YES, not NO as you say. Division by 0 does not throw an exception in JavaScript, it simply results in Infinity (except 0/0 results in NaN), so the second option simply divides 2/0 with no exception, meaning the “unhandled JavaScript function runs”, as the option states.
Option 3 is NO, since the function explicitly throws() and the JavaScript function does NOT run to completion.
This is of course presuming “unhandled JavaScript function runs” means “run to completion without throwing errors”.
Aaaaand I just saw the function called “unhandled” at the top of the question, D’OH!
So it’s NO, NO, YES.
Re Option 2: division of two strings ‘3’/’0′ does not throw an exception. The “unhandled” function will not run.
Re Option 3: the function explicitly throws which will trigger the “unhandled” function to run.
1. the result is the string concatenation ’23’, because the val() function returns a string content. In order to add numeric vales they must be parsed first.
2. the values are numeric, so no custom exception is thrown. A divion between strings is attempted, instead. So, as before, an unhanled exceptin is thrown.
3. one of the values is not numeric, so the function throws the custom exception. This is captured by the generic error handler, hence the unhandled function runs.
So the answer should be NYY.
(tested with Chrome console)
Can someone explain why values we put in the input boxes are “seen” as strings in the 1st statement & why they are “seen” as numbers in the 2nd statement?