Explain Implicit Type Coercion in javascript.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our W3Make Forum to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Type coercion is the automatic or implicit conversion of values from one data type to another (such as strings to numbers). Type conversion is similar to type coercion because they both convert values from one data type to another with one key difference — type coercion is implicit whereas type conversion can be either implicit or explicit.
Examples
Copy to Clipboard
In the above example, JavaScript has coerced the
9
from a number into a string and then concatenated the two values together, resulting in a string of59
. JavaScript had a choice between a string or a number and decided to use a string.The compiler could have coerced the
5
into a number and returned a sum of14
, but it did not. To return this result, you’d have to explicitly convert the5
to a number using theNumber()
method: