menu

JavaScript Basic Programs for Beginners


1.

What is the output of the following code snippet?

console.log(Math.random() * 10);

a random number between 1 and 10

a random number between 0 and 10

10

null


2. Which of the following is the correct way to access an element in an array in JavaScript?

myArray[elementIndex]

elementIndex.myArray

myArray[elementValue]

myArray[elementIndex][elementValue]


3. Which of the following is the correct way to concatenate two strings in JavaScript?

string1.concat(string2);

string1 + string2;

string1.join(string2);

string1.append(string2);


4.

What is the output of the following code snippet?

console.log("hello".toUpperCase());

hello

HELLO

null

undefined


5.

What is the output of the following code snippet?

console.log(3 === "3");

1

0

null

undefined


6.

What is the output of the following code snippet?

console.log(5 > 2 && 2 < 4);

1

0

null

undefined


7.

What is the output of the following code snippet?

console.log(2 + "3");

23

5

null

undefined


8.

What is the output of the following code snippet?

console.log(typeof undefinedVariable);

number

string

boolean

undefined


9.

What is the output of the following code snippet?

console.log(Math.floor(4.7));

4.7

5

4

0.7


10.

What is the output of the following program?

 console.log(3 + 4 + "5");

12

75

345

7+5