menu

JavaScript Basic Programs for Beginners


1.

What is the output of the following program?

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

12

75

345

7+5


2.

What is the output of the following program?

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

HELLO

hello

hElLo

null


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

parseInt(string);

Number(string);

parseFloat(string);

All of the above


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


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. Which of the following is NOT a valid JavaScript data type?

number

string

array

tuple


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


8.

What is the output of the following code snippet?

console.log(2 * "3");

5

6

9

23


9.

What is the output of the following code snippet?

console.log("hello".slice(1, 3));

hel

el

llo

null


10.

What is the correct syntax for declaring a JavaScript variable?

var x;

x = var;

variable x;

x = variable;