Q
Which method is used to convert a string to a number in JavaScript?

Answer & Solution

Answer: Option B
Solution:
The parseInt() method is used to convert a string to an integer (whole number) in JavaScript.
Related Questions on Average

What is the keyword used to declare variables in JavaScript?

A). let

B). variable

C). var

D). const

Which keyword is used to declare a constant variable in JavaScript?

A). const

B). let

C). var

D). constant

What will be the output of the following code: console.log(parseInt('10.5'));?

A). 10

B). 5

C). '10.5'

D). NaN (Not a Number)

What will be the output of the following code: console.log('Hello ' + 'World');?

A). Hello World

B). Hello + World

C). Hello +World

D). HelloWorld

Which of the following is NOT a valid variable name in JavaScript?

A). _myVariable

B). 2ndVariable

C). $myVariable

D). my-Variable

Which statement correctly assigns the value true to a boolean variable isLogged in JavaScript?

A). let isLogged = 'true';

B). let isLogged = true;

C). let isLogged = 1;

D). let isLogged = 0;

Which variable declaration is appropriate if you want a variable to hold a constant value throughout the program execution?

A). let

B). var

C). const

D). constant

What is the purpose of the NaN (Not a Number) value in JavaScript?

A). To represent a number that is not a valid JavaScript number

B). To represent a zero value

C). To represent an infinite value

D). To represent an empty string

What will be the value of x after the following code executes: let x = '5' + 5;?

A). '55'

B). 10

C). 5

D). '10'

What will be the output of the following code: console.log(typeof 'Hello');?

A). string

B). number

C). undefined

D). boolean