menu

JavaScript Basic Programs for Beginners


1.

What is the output of the following program?

console.log(typeof "hello");

number

string

boolean

undefined


2.

What is the output of the following code snippet?

console.log("hello".length);

hello

5

null

undefined


3.

What is the output of the following code snippet?

console.log(typeof undefinedVariable);

number

string

boolean

undefined


4. Which of the following is NOT a valid JavaScript data type?

number

string

array

tuple


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


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(3 === "3");

1

0

null

undefined


8.

What is the output of the following program?

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

12

75

345

7+5


9. 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.


10.

What is the output of the following program?

console.log(10 % 3);

1

3.33

3

0.3