menu

JavaScript Basic Programs for Beginners


1. Which of the following is the correct way to remove an element from the end of an array in JavaScript?

myArray.removeLast();

myArray.pop();

myArray.delete(myArray.length);

myArray[myArray.length] = null;


2. Which of the following is the correct way to create a function in JavaScript?

function myFunction() {}

var myFunction = function() {};

myFunction = function() {};

All of the above are correct.


3.

What is the output of the following code snippet?

console.log(2 * "3");

5

6

9

23


4.

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


5.

What is the output of the following code snippet?

console.log("hello".indexOf("l"));

1

2

3

4


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(Math.floor(4.7));

4.7

5

4

0.7


8. Which of the following is the correct way to round a number to the nearest integer in JavaScript?

Math.floor(number);

Math.round(number);

Math.ceil(number);

All of the above


9. Which of the following is the correct way to check if a variable is an array in JavaScript?

if (typeof myArray === "array") {}

if (myArray.isArray()) {}

if (myArray === "Array") {}

if (Array.isPrototypeOf(myArray)) {}


10.

What is the output of the following code snippet?

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

hello

HELLO

null

undefined