+ 4

What is meant by implicit coercion in Javascript ?

It has got to do something with variables and data type i dunno exactly please help me understand with example if anyone knows...

13th Aug 2017, 12:03 PM
Kalo 'smi
Kalo 'smi - avatar
7 Answers
+ 1
as far as i know, PHP has some sort of implicit coercion that is so cool, but works different from javascript .. let me show you how by using two simple examples: if you add a string to a number using the plus sign (+) then php will automatically assumes that you are trying to make a calculation and hence it coerces/converts the string into a number like so: 4 + "4" = 8 however, if you add a string to a number using the dot operator (.) then it will coerce the number into a string as it will assume that you are trying to concatenate two strings together .. like so: 4 . "4" = 44
13th Aug 2017, 4:01 PM
Medhat Youssef
Medhat Youssef - avatar
+ 4
Thanks bro is this true only for Javascript ?
13th Aug 2017, 3:26 PM
Kalo 'smi
Kalo 'smi - avatar
+ 4
thanks man great answer..
14th Aug 2017, 6:19 AM
Kalo 'smi
Kalo 'smi - avatar
+ 2
implicit: means happening behind the scenes by the javascript engine that handles your code. coercion: in Javascript means converting a type into another type. implicit coercion: simply means that javascript engine converts a data type without asking your permission into another type depending on how much relevant it is. example: var a = 4; var b = "4"; console.log(a + b); This will output 44 instead of 8 .. because javascript coerced/converted the a variable from number into a string
13th Aug 2017, 1:28 PM
Medhat Youssef
Medhat Youssef - avatar
13th Aug 2017, 4:13 PM
Medhat Youssef
Medhat Youssef - avatar
+ 1
and this simple one for javascript: https://code.sololearn.com/W04i6LXsUXv4/?ref=app
13th Aug 2017, 4:28 PM
Medhat Youssef
Medhat Youssef - avatar
0
You're welcome any time bro.
14th Aug 2017, 6:25 AM
Medhat Youssef
Medhat Youssef - avatar