menu

JavaScript Datatypes and Variables


1. What is the data type of a variable that stores an object in JavaScript?

Object

Array

Dictionary

Set


2. What is the result of the following code snippet: typeof undefined;

Undefined

null

undefined

None of the above


3. Which of the following is a valid way to convert a string to a number in JavaScript?

parseInt("10");

10.toInt();

10.toNumber();

Number("10");


4. Which of the following is not a valid way to declare and initialize an object in JavaScript?

var myObj = {};

let myObj = {key1: "value1", key2: "value2"};

const myObj = {key1: "value1", key2: "value2"};

myObj = {key1: "value1", key2: "value2"};


5. Which of the following is not a valid way to declare and initialize a variable in JavaScript?

var myVar = 1;

myVar = 1;

let myVar = 1;

const myVar = 1;


6. Which of the following is not a valid way to declare a function in JavaScript?

function myFunc() {}

let myFunc = function() {};

const myFunc = () => {};

All of the above are valid


7. Which of the following is a valid way to declare a variable with global scope in JavaScript?

var myVar;

let myVar;

const myVar;

All of the above


8. Which of the following is a valid way to declare a constant in JavaScript?

var myConst = 1;

let myConst = 1;

const myConst = 1;

const = 1;


9. Which of the following is not a valid way to declare a constant in JavaScript?

const MY_CONST = "Hello";

const myConst = "World";

var myConst = "JavaScript";

let myConst = "Programming";


10. Which of the following is not a primitive data type in JavaScript?

Number

String

Object

Boolean