Knowledge check: Advanced JavaScript Features

11. What will print out when the following code runs?

const meal = ["soup", "steak", "ice cream"]
let [starter] = meal;
console.log(starter);

  • soup
  • ice cream
  • steak

12. The for-of loop works for Object data types.

  • true
  • false

13. What will print out when the following code runs?

let food = "Chocolate";
console.log(`My favourite food is ${food}`);

  • My favourite food is Chocolate
  • My favourite food is ${food}

14. What values will be stored in the set collection after the following code runs?

let set = new Set();
set.add(1);
set.add(2);
set.add(3);
set.add(2);
set.add(1);

  • 1, 2, 3, 2, 1
  • 1, 2, 3

15. What value will be printed out when the following code runs?

let obj = {
key: 1,
value: 4
};

let output = { ...obj };
output.value -= obj.key;

console.log(output.value);

  • 1
  • 2
  • 3
  • 4

16. What value will be printed out when the following code runs?

function count(...basket) {
console.log(basket.length)
}

count(10, 9, 8, 7, 6);

  • 10, 9, 8, 7, 6
  • 1, 2, 3, 4, 5
  • 6
  • 5

Knowledge Check - JavaScript in the browser

17. In the following code, the type attribute can be omitted.

< script type="text/javascript">
//Comment
< /script >

  • true
  • false

18. What does the document variable return in JavaScript?

console.log(document);

  • The entire body tag of the webpage in the browser’s memory, as a JavaScript object.
  • The entire webpage in the browser’s memory, as a JavaScript object.
  • The HTML code of the downloaded webpage, as a JavaScript string.

Shuffle Q/A 2

19. What does the following function return?

getElementById('main-heading')

  • It doesn’t return anything.
  • All elements that have the class attribute with a value main-heading
  • The first element that has the id attribute with a value main-heading
  • The last element that has the id attribute with a value main-heading

20. After the following code is run, what will happen when the user clicks on a p element in the browser?

document.querySelector('h1').addEventListener('click',
function() {
console.log('clicked');
});

  • ‘clicked’ is printed to the console log.
  • Nothing.

Leave a Reply