Course: JavaScript

Progress (0%)

  1. Foundation

  2. Numbers

  3. Strings

  4. Conditions

  5. Loops

  6. Arrays

  7. Functions

  8. Objects

  9. Exceptions

  10. HTML DOM

  11. CSSOM

  12. Events

  13. Drag and Drop

  14. opt Touch Events

  15. Misc

  16. Project: Analog Clock

JavaScript Data Types Quiz

Quiz 2 19 questions

Prerequisites for the quiz

  1. JavaScript Data Types

Are you ready?

19 questions to solve

Instructions
  1. This quiz goes to full-screen once you press the Start button.
  2. At the end of the quiz, you are able to review all the questions that you answered wrong and see their explanations.
Which of the following values are primitives?
Numbers, strings and booleans, all in their literal forms belong to the primitive category of JavaScript's data types. The correct answer is therefore C. For more details, refer to JavaScript Data Types — Primitives and objects.
A primitive value has properties and methods on it. True or false?
A primitive value is one that has no properties and methods attached to it. Hence, the correct choice is (B). For more details, refer to JavaScript Data Types — Primitives and objects.
document is a primitive value. True or false?
document is not a primitive value since it has properties and methods attached to it. One of these is write() which we have been using throughout the previous chapters. Hence, the correct choice is (B). For more details, refer to JavaScript Data Types — Primitives and objects.
Which one of the following is a floating-point number?
A floating-point number has a decimal point in it. This only applies to choice (B). Choice (C) is a string, not a float. For more details, refer to JavaScript Data Types — Numbers.
JavaScript has separate data types for integers and floats. True or false?
JavaScript has only one type for intergers and floats and that is Number. Hence, the correct choice is (B). For more details, refer to JavaScript Data Types — Numbers.
What does the following code log?
var s = 'Hello';
console.log(s[1]);
s[1] returns the second character of s, which is 'e'. Hence, the correct choice is (B). For more details, refer to JavaScript Data Types — Strings.
How to retrieve the total number of characters of a string s?
The total number of characters of a string is known as its length and could be retrieved by accessing the length property on the string. Hence, the correct choice is (B). For more details, refer to JavaScript Data Types — Strings.
Which of the following denotes a Boolean in JavaScript?
true and false are the Boolean values in JavaScript. They are case-sensitive in nature. Hence, none of the following denotes a Boolean. This goes with choice (D). For more details, refer to JavaScript Data Types — Booleans.
In the code below, what is the value stored in the variable a called?
var a = [1, 2, 3];
[1, 2, 3] is called an array. This goes with choice (B). For more details, refer to JavaScript Data Types — Arrays.
Which of the following represents array literals?
[] are array literals. This goes with choice (B). For more details, refer to JavaScript Data Types — Arrays.
Arrays are mutable in nature. True or false?
Arrays are indeed mutable in nature i.e. they can be modified in-place. Hence, the given statement is true. For more details, refer to JavaScript Data Types — Arrays.
Strings are immutable in nature. True or false?
Strings are immutable in nature i.e. they can't be modified once created. Hence, the given statement is true. For more details, refer to JavaScript Data Types — Strings.
What does the following code log?
var chars = ['z', 'c' ,'a', 'l'];
console.log(chars.sort());
chars.sort() sorts the array chars in alphabetical order. It returns ['a', 'c', 'l', 'z'] and this goes with choice (A). For more details, refer to JavaScript Data Types — Arrays.
Functions in JavaScript are also called?
Functions are objects that could be called, likewise they are also known as callable objects. This goes with choice (D). For more details, refer to JavaScript Data Types — Functions.
Which of the following keywords is used to denote a function in JavaScript?
function is the keyword that denotes a function in JavaScript. Hence, the correct choice is (D). For more details, refer to JavaScript Data Types — Functions.
Identify the parameter in the code below:
function sayHello(name) {
    console.log('Hello ' + name);
}

sayHello('Programmer');
A parameter is an identifier mentioned in the pair of parentheses (()) while defining a function. In this case, it's the identifier name. The correct choice is therefore (A). For more details, refer to JavaScript Data Types — Functions.
What does the following code log?
console.log(typeof 's');
typeof on strings returns the value 'string'. This aligns with choice (A). For more details, refer to JavaScript Data Types — typeof.
What does the following code log?
console.log(typeof []);
typeof returns 'object' for all non-primitive values, except for functions. That is, typeof [] returns 'object'. This aligns with choice (B). For more details, refer to JavaScript Data Types — typeof.
What does the following code log?
console.log(typeof null);
typeof null returns the value 'object'. This is an official bug in the implementation of JavaScript that hasn't been rectified to date because doing so would break many code snippets out there. Hence, the correct choice is (B). For more details, refer to JavaScript Data Types — typeof.