JavaScript Post Course Assessment

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By James Richardson
J
James Richardson
Community Contributor
Quizzes Created: 13 | Total Attempts: 10,987
Questions: 10 | Attempts: 106

SettingsSettingsSettings
JavaScript Post Course Assessment - Quiz


Questions and Answers
  • 1. 

    How do you create a function named coolFunction?

    • A.

      Function coolfunction () {}

    • B.

      Function=coolFunction()

    • C.

      Function:coolFunction(){}

    • D.

      Function coolFunction () {}

    Correct Answer
    D. Function coolFunction () {}
    Explanation
    The correct answer is "function coolFunction () {}". This is the correct way to create a function named coolFunction in JavaScript. The function keyword is used to declare a function, followed by the function name (coolFunction in this case), parentheses for any parameters, and curly braces to enclose the function body.

    Rate this question:

  • 2. 

    To display text ‘’message’ along with the value contained in variable msg, an alert box should be called via:

    • A.

      Call alert ('message' + msg);

    • B.

      Alert ('message' + msg);

    • C.

      AlertBox ('message' + msg);

    • D.

      All of the above

    Correct Answer
    B. Alert ('message' + msg);
    Explanation
    To display the text 'message' along with the value contained in the variable msg, the correct way is to call the alert box using the syntax alert ('message' + msg). This will concatenate the string 'message' with the value of the variable msg and display it in an alert box. The other options, such as call alert, alert, and alertBox, are incorrect syntax and will not display the desired result.

    Rate this question:

  • 3. 

     In a JS statement, what is the difference between a++  vs ++a where a is a variable:

    • A.

      A++ increments the value of a by 1, ++a is incorrect

    • B.

      Both are same and increment the value of a by 1

    • C.

      Both increments the value of a by 1 but a++ does it after assignment and ++a does it before assignment

    • D.

      Both are wrong and will cause an error in the code

    Correct Answer
    C. Both increments the value of a by 1 but a++ does it after assignment and ++a does it before assignment
    Explanation
    The difference between a++ and ++a is that a++ increments the value of a by 1 after the assignment, while ++a increments the value of a by 1 before the assignment.

    Rate this question:

  • 4. 

    Which of these is not a comparison operator?

    • A.

    • B.

      >

    • C.

      =

    • D.

      !=

    Correct Answer
    C. =
    Explanation
    The equal sign (=) is not a comparison operator, but an assignment operator. It is used to assign a value to a variable, rather than comparing two values. Comparison operators are used to compare values and include operators such as greater than (>), less than (=), less than or equal to (

    Rate this question:

  • 5. 

    Which command skips the rest of a case statement?

    • A.

      Return

    • B.

      Exit

    • C.

      Continue

    • D.

      Break

    Correct Answer
    D. Break
    Explanation
    The correct answer is "break". In a case statement, the break command is used to exit the switch statement and skip the remaining cases. It is often used to prevent fall-through, where execution continues to the next case even after a match is found. By using break, the program will jump to the end of the switch statement, allowing it to continue executing the code after the switch block.

    Rate this question:

  • 6. 

     How can you reference part of a string starting from 4th character and containing a total of 5 characters contained in var str? (e.g. from a string “hello world!”, it should return “lo wo”).

    • A.

      Str.substr(4,9);

    • B.

      Str.part(3,5);

    • C.

      Str.substr(3,5);

    • D.

      Str.part(4,9);

    Correct Answer
    C. Str.substr(3,5);
    Explanation
    The correct answer is `str.substr(3,5)` because the `substr()` method in JavaScript is used to extract a portion of a string, starting from the specified index and containing the specified number of characters. In this case, `str.substr(3,5)` will start from the 4th character (index 3) and return a string with 5 characters.

    Rate this question:

  • 7. 

    Which event do you use to run something after the page has finished loading?

    • A.

      Onfinished

    • B.

      Onload

    • C.

      Onunload

    • D.

      Oncomplete

    Correct Answer
    B. Onload
    Explanation
    The correct answer is "onload". The "onload" event is used to run something after the page has finished loading. This event is commonly used to trigger functions or scripts that require the page's content to be fully loaded before executing. It ensures that all elements, including images and external resources, have been loaded and are ready to be manipulated or interacted with.

    Rate this question:

  • 8. 

    How do you define a "for" loop which starts from 0, goes till 5 and increments by 1 after each iteration?

    • A.

      For (i

    • B.

      For i = 0 to 5 {…}

    • C.

      For (i = 0; i

    • D.

      For (i = 0; i

    Correct Answer
    D. For (i = 0; i
    Explanation
    The correct answer is "for (i = 0; i < 6; i++)". This is the correct syntax for defining a "for" loop that starts from 0, goes till 5, and increments by 1 after each iteration. The loop will continue as long as the value of "i" is less than 6, and after each iteration, the value of "i" will be incremented by 1.

    Rate this question:

  • 9. 

     What is the correct way to write a JavaScript array?

    • A.

      Var txt = new Array ="tim","kim","jim";

    • B.

      Var txt = new Array("tim","kim","jim");

    • C.

      Var txt = new Array:1=("tim")2=("kim")3=("jim");

    • D.

      Var txt = new Array(1:"tim",2:"kim",3:"jim");

    Correct Answer
    B. Var txt = new Array("tim","kim","jim");
    Explanation
    The correct way to write a JavaScript array is by using the syntax var txt = new Array("tim","kim","jim"). This creates an array named "txt" with three elements: "tim", "kim", and "jim".

    Rate this question:

  • 10. 

    What will the statement mentioned below will do? result =  (testCond == 1) ? “pass” : “fail”;

    • A.

      Will return error as this is not a valid statement in JS.

    • B.

      If testCond is equal to 1 then result will contain an array with two elements pass and fail.

    • C.

      If testCond is equal to 1 then result will contain string pass otherwise it will be set to fail.

    • D.

      Result will contain value of testCond if the testCond is equal to 1

    Correct Answer
    C. If testCond is equal to 1 then result will contain string pass otherwise it will be set to fail.
    Explanation
    The statement mentioned will assign the value "pass" to the variable "result" if the condition "testCond == 1" is true. Otherwise, it will assign the value "fail" to the variable "result".

    Rate this question:

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Feb 23, 2024
    Quiz Edited by
    ProProfs Editorial Team
  • Apr 01, 2013
    Quiz Created by
    James Richardson
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.