In the name of ALLAH, the most beneficient, the most merciful

MCQs 1 (JavaScripting)

Multiple Choice Questions

  1. A(n) ________ can hold a collection of named values, known as properties.

    1. data type
    2. object
    3. property
    4. temp
  2. What output will be displayed on the document when the following loop completes?
    for(x = 0; x < 4; x++){
    document.write(x + " ");
    }

    1. x x x x
    2. 0 1 2 3
    3. 0 1 2 3 4
    4. x x x x x
  3. Which of the following statements declares a variable named score?

    1. score;
    2. variable score;
    3. var score;
    4. declare var score;
  4. A complete line of JavaScript code that can be executed by the computer is called a(n) ________.

    1. block
    2. statement
    3. executable
    4. variable
  5. var myVar = "23";
    What is the data type of the variable myVar?

    1. number
    2. string
    3. boolean
    4. double
  6. Consider the following object:
    var book = {
    title: "Romeo and Juliet",
    author: "William Shakespeare",
    publishDate: 1597
    };

    Considering the book object above,
    author is a ________ of the book object.

    1. value
    2. property
    3. object
    4. data type
  7. Which of the following statements invokes a function named myFunction that has no parameters?

    1. myFunction;
    2. myFunction();
    3. myFunction[];
    4. myFunction!
  8. var x = 4;
    var y = 9;
    var z = x < y;

    What is the data type of the variable z above?

    1. boolean
    2. number
    3. string
    4. double
  9. Which alert message(s) will be displayed when the following code runs?
    var num = 35;
    if(num <= 30) {
    document.write("Alert message #1");
    }
    else{
    document.write("Alert message #2");
    }

    1. "Alert message #1"
    2. "Alert message #2"
    3. Neither
    4. Both
  10. Consider the variable:
    var greeting = "Hello";
    greeting += "John";

    What value is stored in the greeting variable after the 2nd line of code?

    1. "Hello John"
    2. HelloJohn
    3. "John"
    4. "HelloJohn"
  11. What is the result of the following statement?
    typeof 340.2

    1. decimal
    2. number
    3. string
    4. object
  12. JavaScript allows you to develop webpages that are ________. This means the webpage's content changes based on conditions and interactions.

    1. static
    2. dynamic
    3. encapsulated
    4. inherited
  13. Which alert message(s) will be displayed when the following code runs?
    var num = 42;

    if(num <= 30)
    {
    document.write("Alert message #1");
    }
    else{
    document.write("Alert message #2");
    }

    1. "Alert message #1"
    2. "Alert message #2"
    3. Neither
    4. Both
  14. A JavaScript variable that originally stored a number can later store a string value.

    1. True
    2. False
  15. Which of the following statements invokes a function named myFunction that accepts a numeric parameter?

    1. myFunction 4;
    2. myFunction(4);
    3. myFunction <-(4);
    4. myFunction[4];
  16. A JavaScript script will always be executed after the HTML page finishes loading.

    1. True
    2. False
  17. JavaScript statements end with ________.

    1. a semicolon (;)
    2. forward slashes (//)
    3. back slashes (\\)
    4. a period (.)
  18. JavaScript is a(n) ________.

    1. isolated language
    2. Java variant
    3. scripting language
    4. compiled language
  19. Consider the following code:
    var x = 2;
    var y = 6;
    var z = -3;

    Which of the following line of code will update the stored value of the variable y to 3?

    1. y = x
    2. y /= 2;
    3. y = z
    4. y == 3
  20. What causes a loop to be infinite?

    1. It does not include a statement that modifies the test/condition.
    2. It does not include a closing brace
    3. It does not have a return statement
    4. It does not have a proper condition
  21. Which of the following lines of code produces the value "William Shakespeare"?

    1. book.authorFirstName + book.authorLastName
    2. book.authorFirstName.authorLastName
    3. book.authorFirstName + " " + book.authorLastName
    4. book{authorFirstName+authorLastName}
  22. A ________ is a container that can store a value in your program that can be accessed or modified at a later point.

    1. temp
    2. block
    3. variable
    4. segment
  23. What value is stored in the variable x after the following lines of code are executed?
    var x = 3;
    x*=2;

    1. 2
    2. 3
    3. 6
    4. 9
  24. Which of the following statements declares a (non-global) variable named myNum and assigns it a value of 24?

    1. myNum = 24;
    2. variable myNum set to 24;
    3. num myNum 24;
    4. var myNum = 24;
  25. How can a function return a value?

    1. return the value in the body of the function with the return keyword
    2. include a return statement after the body of the function
    3. include the return keyword in the parameter list( ) use the function return (parameter1, parameter2) syntax
    4. none of the given
  26. What will the value of x be when the following while loop stops executing?
    var x = 4;
    while(x > 0)
    {
    alert("Hello ");
    x--;
    }

    1. 4
    2. 0
    3. 1
    4. this is an infinite loop- will never stop executing
  27. Consider the following code:
    var x = 2;
    var y = 6;
    var z = -3;

    What is the datatype of the variable **z**?

    1. number
    2. negative
    3. int
    4. whole
  28. What belongs immediately after the if keyword in an if statement, within the parentheses?
    if ( )

    1. An else statement
    2. A return statement
    3. A condition
    4. A number
  29. var language = "JavaScript";
    The data type of the language variable above is:

    1. number
    2. string
    3. boolean
    4. double
  30. What is an infinite loop?

    1. A loop that contains many lines of code
    2. A loop that never stops iterating
    3. A loop that doesn't have a return statement
    4. A loop that doesn't have a closing brace
  31. Consider the following code:
    var x = 2;
    var y = 6;
    var z = -3;

    Which of the following line of code will update the stored value of the variable y to 3?

    1. y = x
    2. y = -z;
    3. y = z
    4. y == 3
  32. Which of the following statements declares a variable named highScore?

    1. new var highScore;
    2. variable highScore;
    3. var highScore;
    4. declare var highScore;
  33. Which message will be displayed on the document when the following code is executed?
    var x = 3;
    var y = 8;
    if(x % 2 == 1 && y > 6)
    {
    document.write("This test passed" );
    }
    else{
    document.write("This test failed");
    }

    1. This test passed
    2. This test failed
    3. Neither message will be displayed
    4. Both messages will be displayed
  34. Consider the code:
    var greeting = "Hello";

    var contact = {
    firstName: "Jane",
    lastName: "Doe",
    age: 35
    };

    What line of code update the greeting variable to store the value "Hello Jane"?

    1. greeting += firstName;
    2. greeting += contact.firstName;
    3. greeting += " " + contact.firstName;
    4. greeting = greeting + " " + contact.lastName;
  35. var x = 25;
    var y = 12;
    var z = x < y;

    What is the data type of the variable z above?

    1. string
    2. number
    3. boolean
    4. object
  36. var x = 34;
    var y = 10;
    var z = x%y;

    What value is stored in the variable z after the following lines of code are executed?

    1. 2
    2. 4
    3. 5
    4. 3
  37. Consider the following object:
    var book = {
    title: "Romeo and Juliet",
    author: "William Shakespeare",
    publishDate: 1597
    };

    Considering the book object above,
    which line of code will write the publish date of the book object to the browser console?

    1. console.log(book.publishDate);
    2. console.log(book.author);
    3. console.log(publishDate);
    4. console.log(book.title);
  38. typeof -34.7

    1. number
    2. string
    3. boolean
  39. var x = 25;
    var y = 12;
    var z = x < y;

    What value is stored in the variable z above?

    1. true
    2. false
    3. 12
    4. 25
  40. Consider the following code:
    var book = {
    title: "Romeo and Juliet",
    authorFirstName: "William",
    authorLastName: "Shakespeare",
    publishDate: 1597
    };

    What line of code logs the value of the title property to the console?

    1. console.log(book.authorLastName);
    2. console.log(book.authorFirstName);
    3. console.log(book.title);
    4. console.log(book.publishDate);
  41. Consider the following code:
    var x = 2;
    var y = 6;
    var z = -3;

    Which of the following line of code will update the stored value of the variable y to 3?

    1. y = x
    2. y = y/x;
    3. y = z
    4. y == 3
  42. JavaScript code is case sensitive.

    1. True
    2. False
  43. Which statement retrieves the element "d" from the array myArray?
    var myArray = ["a", "b", "c", "d", "e"];

    1. myArray["d"]
    2. myArray[4]
    3. myArray[3]
    4. myArray.getElement(4)
  44. Which message will be displayed on the document when the following code is executed?
    var x = 3;
    var y = 8;
    if(x < 5 && y > 6) {
    document.write("This test passed");
    }
    else{
    document.write("This test failed");
    }

    1. This test passed
    2. This test failed
    3. Neither message will be displayed
    4. Both messages will be displayed
  45. Which of the following statements defines a function named increment that returns a value and defines a parameter?

    1. increment(num){
      num++;}
      return num;
    2. increment(num){
      num++;
      return num;}
    3. function increment(num){
      num++;
      return num;}
    4. func increment(num){
      param: num;
      num++;
      return (num);}
  46. typeof "390"
    What is the result of the this statement?

    1. boolean
    2. number
    3. string
    4. object
  47. Consider the code:
    var greeting = "Hello";

    var contact = {
    firstName: "Jane",
    lastName: "Doe",
    age: 35
    };

    What line of code update the greeting variable to store the value "Hello Jane"?

    1. greeting += firstName;
    2. greeting += contact.firstName;
    3. greeting = greeting + " " + contact.firstName;
    4. greeting = greeting + " " + contact.lastName;
  48. Which of the following statements stores a value returned from a function?

    1. var value = myFunction;
    2. var value = myFunction();
    3. myFunction -> var value;
    4. var value = return myFunction;
  49. Which of the following can be used to modify the text within a paragraph?

    1. element.displayText
    2. document.write
    3. element.write
    4. element.innerHTML
  50. var x = 4;
    var y = 9;
    var z = x < y;

    What value is stored in the variable z above?

    1. 4
    2. 9
    3. true
    4. false
  51. Which of the following are used to create a variable and assign it a value?

    1. data type and identifier
    2. identifier and a value
    3. value and an assignment operator (=)
    4. data type, identifier, value and an assignment operator (=)
  52. Which line of code creates a variable named language that holds that value "JavaScript"?

    1. variable language: "JavaScript";
    2. var language: JavaScript;
    3. var language = JavaScript;
    4. var language = "JavaScript";
  53. Which of the following does not output information to the user via the webpage?

    1. window.alert
    2. console.log
    3. document.write
    4. element.innerHTML
  54. typeof "-34.7"

    1. number
    2. string
    3. boolean
  55. Which statement retrieves the element with the value 32 from the array numbers?
    var numbers = [1, 3, 12, 42, 32, 4];

    1. numbers.get(32)
    2. numbers[32]
    3. numbers[4]
    4. numbers[5]
  56. Which message will be displayed on the document when the following code is executed?
    var num = 24;
    if(num > 82)
    {
    document.write("zone 1");
    }
    else if(num >= 43)
    {
    document.write("zone 2");
    }
    else{
    document.write("zone 3");
    }

    1. zone 1
    2. zone 2
    3. zone 3
    4. none of the given
  57. What value is stored in the variable x after the following lines of code are executed?
    var x = 9;
    var y = 3;
    var z = x%y;

    1. 0
    2. 1
    3. 2
    4. 3
  58. Which of the following for-loop declarations creates a loop that will execute 4 times?

    1. for(x = 1; x < 4; x++)
    2. for(x = 1; x < 5; x++)
    3. for(x = 1; x < 3; x++)
    4. for(x = 0; x < 5; x++)
  59. What is the primary role of JavaScript?

    1. To translate Java for webpages
    2. To style web content
    3. To add dynamic behavior to webpages
    4. To store and retrieve data from databases
  60. typeof "Hello, world"

    1. number
    2. string
    3. boolean
  61. In order to write JavaScript code that is embedded in an HTML file, your JavaScript code belongs ________.

    1. at the top of the HTML file
    2. within a script element
    3. within a javascript element
    4. at the end of the HTML file
  62. Which of the following for-loop declarations creates a loop that will execute 4 times?

    1. for(x = 1; x < 4; x++)
    2. for(x = 0; x < 4; x++)
    3. for(x = 1; x < 3; x++)
    4. for(x = 0; x < 5; x++)
  63. Assume that a variable has been declared and initialized with the following statement:
    var count = 4;
    Which of the following statements updates the variable with the value 24?

    1. var count = 24;
    2. update count 24;
    3. count == 24;
    4. count = 24;
  64. Which of the following statements calls a function, giveMeANumber, and passes the number 4 as a parameter?

    1. giveMeANumber();
    2. giveMeANumber().4;
    3. giveMeANumber(4);
    4. giveMeANumber(==4);
  65. Which of the following keywords is used to define a function?

    1. function
    2. func
    3. new
    4. method
  66. Consider the following code:
    var book = {
    title: "Romeo and Juliet",
    authorFirstName: "William",
    authorLastName: "Shakespeare",
    publishDate: 1597
    };

    The code above creates a(n) ________ with the identifier book.

    1. property
    2. object
    3. value
    4. data type
  67. Which message will be displayed on the document when the following code is executed?
    var num = 40;
    if(num > 60) {
    document.write("zone 1");
    }
    else if(num > 25) {
    document.write("zone 2");
    }
    else{
    document.write("zone 3");
    }

    1. zone 1
    2. zone 2
    3. zone 3
    4. none of the above
  68. Which statement creates an array named colors and stores 4 elements?

    1. var colors = ["red", "orange", "yellow", "green"];
    2. var colors = array["red", "orange", "yellow", "green"];
    3. var colors = new array("red", "orange", "yellow", "green");
    4. var colors = array: ["red", "orange", "yellow", "green"];