Type Coercion is process of automatic or implicit conversion of value from one data type to another. Conversion from Number to String , String to Number, Boolean to Number and so on. Type coercion occurs when different types of operators are applied to the values
Note : It occur only with "+" operator
Note : The string should be a Number
📌 Boolean to Number : when a boolean is added to a Number, boolean value is converted to number as 0 for "false" and 1 for "true"
📌 Equality Operator : The equality ( == ) is used to compare value irrespective of their type. This happen by coercion of Non-Number to Number data type
Note : To avoid type coercion, use the triple-equals operator ( === )
Top comments (0)