Javascript: The Hidden Parts (Implicit and Automatic)

Andrew Mc
Andrew Mc
Jun 13 · 6 min read
Photo by Isis França on Unsplash

Automatic Semicolon Insertion

return;
a+b;

Implicit Coercion

"2" + 1 = "21"
"2" - 1 = 1
1 + 1 + "2" = "12"
true + true = 2
3 + [1] = "31"
3 * [ 1 ] = 3
3 * [ 1, 2] = NaN
"2" + String(1) = "21"
Number("2") - 1 = 1
String(1 + 1) + "2" = "22"
String(3) +[ 1 ].join() = "31"
3 * Number([ 1 ].join()) = 3
3 * Number([ 1, 2 ].join()) = NaN //this comes from Number("1,2") which equals NaN
if(testVal){
throw error
}

Implicit Return

const testFunc = () => 'It worked!';
const testFunc2 = () => {'It worked!'};const testFunc3 = () => {return 'It worked!'};
const testFunc4 = () => {workingVal:'It worked!'};const testFunc5 = () => ({workingVal:'It worked!'});

Implicit Function Params

function arguementTest () {
return arguments.length
}
arguementTest(0,1,2,3) // this will return 4
function restOp ( one, two, ...rest){
return rest
}
restOp (0,1,2,3,4) // this will return [2,3,4]

Outro

The Startup

Medium's largest active publication, followed by +479K people. Follow to join our community.

Andrew Mc

Written by

Andrew Mc

Life and death and love and birth, and peace and war on the planet Earth. https://github.com/LaikaFusion

The Startup

Medium's largest active publication, followed by +479K people. Follow to join our community.