Type Coercion
Topic 6JavaScript Part 5 (Important Keywords)
Type Coercion
Introduction
Type coercion is the automatic or implicit conversion of values from one data type to another.
Key Concepts and Definitions
Type Coercion
The automatic or implicit conversion of values from one data type to another.
Implicit Coercion
Automatic conversion performed by JavaScript.
Explicit Coercion
Manual conversion using functions like Number(), String(), Boolean().
Examples
Implicit Coercion:
console.log('5' + 5); // "55" (string concatenation)
console.log('5' - 2); // 3 (string converted to number)Explicit Coercion:
const str = '123';
const num = Number(str);
console.log(num); // 123Interview guide discussion
(0)Join the discussion — login to comment and help other developers.
Login to comment