DEV Community

Discussion on: Variable explanation help:

Collapse
 
nombrekeff profile image
Keff

Concatenation:

const name = 'bob';
const lastName = 'sprinklebutt';

const fullName = name + ' ' + lastName; // Here, name is contatenated with lastName to create a new string
Enter fullscreen mode Exit fullscreen mode

Conversion:

const numString = '1234';
const num = Number(numString); // Convert string to a number
Enter fullscreen mode Exit fullscreen mode

Coercion:

const stringNumber = '12';
const num = 12;
const coerced = stringNumber + num; // Results in "1212"
true == 1; // true
Enter fullscreen mode Exit fullscreen mode

Type coercion is the process of converting value from one type to another (such as string to number, object to boolean, and so on). Any type, be it primitive or an object, is a valid subject for type coercion.
Exerpt from freecodecamp.org/news/js-type-coer...

Truthy and Falsy:
This is a weird one in JS

true == 'true' // true
true == 'false' // true
true == 1 // true
1 == 1 // true
1 == '1' // true
1 == '2' // false
[] == false // true
Enter fullscreen mode Exit fullscreen mode
Collapse
 
nombrekeff profile image
Keff

Hope it's useful

Collapse
 
nceedee profile image
N Cee Dee

thanks man for this,
i really appreciate.

Collapse
 
andrewbaisden profile image
Andrew Baisden

This is a great explanation right here.

Collapse
 
nceedee profile image
N Cee Dee

thanks for this,
very simple to understand

Collapse
 
nceedee profile image
N Cee Dee

wow,
thanks for this

Collapse
 
nceedee profile image
N Cee Dee

Thanks for this..

i really appreciate