menu

JavaScript Datatypes and Variables


1. Which of the following is a valid way to concatenate two strings in JavaScript?

str1 .concat(str2)

str1 + str2

str1 - str2

str1 * str2


2. Which of the following is a valid way to declare and initialize an array with multiple values in JavaScript?

var myArr = [1, 2, 3];

let myArr = {1, 2, 3};

const myArr = [1, 2, 3];

Only A and C


3. Which of the following is a valid way to check the data type of a variable in JavaScript?

typeof myVar;

myVar.type();

myVar.getType();

typeOf(myVar);


4. Which of the following is a valid way to declare a variable in JavaScript?

var myVar = 1;

let myVar = 1;

const myVar = 1;

All of the above


5. Which of the following is a valid way to declare an empty array in JavaScript?

var myArr = [];

let myArr = {};

const myArr = ();

All of the above


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

Undefined

null

undefined

None of the above


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

var myNum = 42;

let myNum = 3.14;

const myNum = -99;

All of the above


8. 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;


9. What is the data type of a variable that stores an undefined value in JavaScript?

Undefined

Null

Object

None of the above


10. Which of the following is a valid way to declare and initialize an object with multiple properties in JavaScript?

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

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

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

All of the above