Q
What is the result of the following code: let x = 5; x = 'hello'; console.log(typeof x);?

Answer & Solution

Answer: Option B
Solution:
The variable x changes its type from number to string when reassigned.
Related Questions on Average

Given the code: let y = 10; y = true;, what is the type of y after execution?

A). number

B). boolean

C). string

D). object

In JavaScript, what will be the type of a variable x after x = 5 + true;?

A). number

B). string

C). boolean

D). undefined

Which type conversion happens automatically in the expression 3 + '5'?

A). Number to String

B). String to Number

C). Boolean to String

D). Number to Boolean

What happens when you add a number and a string in JavaScript?

A). An error is thrown

B). The number is converted to a string

C). The string is converted to a number

D). Both are converted to boolean

What will be the result of the following code: let z = '123'; z = Number(z); console.log(typeof z);?

A). string

B). number

C). undefined

D). boolean

What does the isNaN function do?

A). Checks if a value is not a number

B). Converts a value to a number

C). Checks if a value is a number

D). Converts a value to NaN

How can you check if a variable is an array in JavaScript?

A). typeof variable === 'array'

B). Array.isArray(variable)

C). variable instanceof array

D). variable.constructor === array

What does it mean that JavaScript is dynamically typed?

A). Variables do not have types

B). Variables can change type

C). Variables must be declared with a type

D). Variables cannot change type

What does the parseInt function do in JavaScript?

A). Converts a number to a string

B). Converts a string to an integer

C). Converts a boolean to a number

D). Converts an array to a number

Which operator is used to determine the type of a variable in JavaScript?

A). typeof

B). instanceof

C). type

D). isType