Javascript quiz questions

Javascript interview questions

  • 1.

    Which of the following is the output of the below JavaScript code?

    function getFunc() {
        var a = 7;
        return function(b) {
            alert(a+b);
        }
    }
    var f = getFunc();
    f(5);
    1. 5

    2. 7

    3. null

    4. undefined

    5. 12

    Answer
  • 2.

    Which of the following functions of Number object would display output in exponential format?

    1. toFixed()

    2. toExponential()

    3. toPrecision()

    4. toLocaleString()

    Answer
  • 3.

    Which of the following is a true statement for JavaScript callbacks?

    1. All except None.

    2. None

    3. Some callbacks are just events, called to give the user a chance to react when a certain state is triggered.

    4. A callback is a plain JavaScript function passed to some method as an argument or option.

    Answer
  • 4.

    Which of the following functions of Number object would return a string version of the number that may change according to the browser’s locale settings?

    1. toExponential()

    2. toFixed()

    3. toLocaleString()

    4. toString()

    Answer
  • 5.

    Select a String function that finds the match between a regular expression and a string, and to replace the matched substring with a new substring?

    1. match()

    2. concat()

    3. replace()

    4. search()

    Answer
  • 6.

    What will the following code return: Boolean(10 > 9)

    1. true

    2. false

    3. NaN

    Answer
  • 7.

    How can you detect the client's browser name?

    1. browser.name

    2. navigator.appName

    3. client.navName

    Answer
  • 8.

    How to insert a comment that has more than one line?

    1. <!--This comment has
      more than one line-->

    2. /*This comment has
      more than one line*/

    3. //This comment has
      more than one line//

    Answer
  • 9.

    Is JavaScript case-sensitive?

    1. No

    2. Yes

    Answer
  • 10.

    Which operator is used to assign a value to a variable?

    1. x

    2. -

    3. =

    4. *

    Answer
  • 11.

    How do you declare a JavaScript variable?

    1. v carName;

    2. variable carName;

    3. var carName;

    Answer
  • 12.

    Which event occurs when the user clicks on an HTML element?

    1. onmouseclick

    2. onmouseover

    3. onclick

    4. onchange

    Answer
  • 13.

    JavaScript is the same as Java.

    1. False

    2. True

    Answer
  • 14.

    What is the correct JavaScript syntax for opening a new window called "w2" ?

    1. w2 = window.open("http://www.w3schools.com");

    2. w2 = window.new("http://www.w3schools.com");

    Answer
  • 15.

    How do you find the number with the highest value of x and y?

    1. Math.ceil(x, y)

    2. top(x, y)

    3. ceil(x, y)

    4. Math.max(x, y)

    Answer
  • 16.

    How do you round the number 7.25, to the nearest integer?

    1. rnd(7.25)

    2. Math.rnd(7.25)

    3. Math.round(7.25)

    4. round(7.25)

    Answer
  • 17.

    What is the correct way to write a JavaScript array?

    1. var colors = ["red", "green", "blue"]

    2. var colors = 1 = ("red"), 2 = ("green"), 3 = ("blue")

    3. var colors = (1:"red", 2:"green", 3:"blue")

    4. var colors = "red", "green", "blue"

    Answer
  • 18.

    How can you add a comment in a JavaScript?

    1. 'This is a comment

    2. <!--This is a comment-->

    3. //This is a comment

    Answer
  • 19.

    How does a FOR loop start?

    1. for (i = 0; i <= 5)

    2. for (i <= 5; i++)

    3. for (i = 0; i <= 5; i++)

    4. for i = 1 to 5

    Answer
  • 20.

    How does a WHILE loop start?

    1. while (i <= 10)

    2. while (i <= 10; i++)

    3. while i = 1 to 10

    Answer

© 2017 QuizBucket.org