PrepAway - Latest Free Exam Questions & Answers

Which values will be returned?

HOTSPOT
You are validating user input by using built-in JavaScript functions.
The application must:
Store the value that is entered in a variable named inputValue
Use the built-in isNaN(tnputValue) function to evaluate the data type
You need to validate the return value of the isNaN(inputValue) function.
Which values will be returned? (To answer, configure the appropriate options in the dialog box in
the answer area.)

PrepAway - Latest Free Exam Questions & Answers

Answer:

19 Comments on “Which values will be returned?

  1. M says:

    Correct answers:

    -13 False
    24.3 False
    3*8 False
    ‘5’ False

    To check this, go to any other website than this, press F12, go to console and enter:
    isNaN(-13) + ‘ ‘ + isNaN(24.3) + ‘ ‘ + isNaN(3*8) + ‘ ‘ + isNaN(‘5’);
    This will produce the following:
    false false false false




    4



    0
  2. S says:

    I’ve some doubts. The task is to validate user input value that we stored in variable named ‘inputValue’.
    So, if user enters value in input, e.g. 3*8 and then we get this value with jQuery:

    var inputValue = $(‘#someInputValue’).val(); // inputValue = ‘3*8’ -> string
    isNaN(inputValue) == true

    Same is if user enter string ‘5’ in input.

    Yes, M is right when we open developer tool and type directly this values into isNaN function we will get everything as false. But the task is to validate user input.

    Can someone give feedback?




    2



    0
  3. Franco2000 says:

    “You’re validating user input”, so if an user inputs “3*8” its obvious that using NAN we’re gonna get True, the same for ‘5’. You’re right S.




    1



    0
  4. Damien says:

    I assume that the user inputs the value into a form and the .val() function is used to get the value. The .val() function returns a string. This is very important to the answer, but only if this assumption is true.

    If you go here: http://www.w3schools.com/jsref/jsref_isNaN.asp

    and click on the first “Try It” you will see a list of isNaN test examples. Change the function contents to:

    var a = isNaN(-13) + “”;
    var b = isNaN(“-13”) + “”;
    var c = isNaN(24.3) + “”;
    var d = isNaN(“24.3”) + “”;
    var e = isNaN(3*8) + “”;
    var f = isNaN(“3*8”) + “”;
    var g = isNaN(‘5’) + “”;
    var h = isNaN(“‘5′”);

    var res = a + b + c + d + e + f + g + h;
    document.getElementById(“demo”).innerHTML = res;

    You will see that the results are:

    false
    false
    false
    false
    false
    true
    false
    true

    The answers given by aiotestking are correct.




    1



    0
  5. Shahid Mahmood Khawaja says:

    Correct Answer is false, false, false, false

    http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_isnan

    The isNaN() function returns true if the value is NaN (Not-a-Number), and false if not.

    Click the button to check whether a number is an illegal number.

    Try it

    function myFunction() {
    var a = isNaN(“-3.2”) + “”;
    var b = isNaN(-1.23) + “”;
    var c = isNaN(5-2) + “”;
    var d = isNaN(0) + “”;
    var e = isNaN(“123”) + “”;
    var f = isNaN(“Hello”) + “”;
    var g = isNaN(“2005/12/12”);

    var res = a + b + c + d + e + f + g;
    document.getElementById(“demo”).innerHTML = res;
    }




    1



    1

Leave a Reply