EasilyBaffled

Danny Michaelis

Why are any of us here?

To fix what ain't broke!

console.ident = 
	v => ( console.log(  v ),  v );

Identity Function

v => v;

Javascript has become an Expressive language

BinaryExpression:

1+1

AssignmentExpression:

x = 1 + 1

ArrowFunctionExpression:

v => v + 1

CallExpression:

[1, 2].map( v => v + 1 )

Async:

callbacks;
`Promise`, `async`;

Iterate:

for( var ... ){ ... }
`map`, `filter`, `reduce`;

Conditional:

if ( bool ) ... else
`bool ? a : b`;

Function:

function ( v ) {}
`v => v`;

Function Composition

const userID = getUserId(
    JSON.parse( localStorage.getItem( 'user' ) )
);
// Uncaught SyntaxError: Unexpected token o in JSON at position 1

Function Composition

const userStr = localStorage.getItem( 'user' )
console.log( userStr )
// "[ object Object ]"

const userID = getUserId(
    JSON.parse( userStr )
);
// Uncaught SyntaxError: Unexpected token o in JSON at position 1

Ternary

Number( val ) ? formatCurrency( str ) : val;
// 0

Ternary

console.log( val, Number( val ), !!Number( val ) );
// 0 0 false
Number( val ) ? formatCurrency( str ) : val;
// 0

Object Construction, Return Expressions

const pickAndFormatTransaction = ( {
    description,
    date,
    amount,
    ...details
 } ) => ( {
    description,
    date: moment( date ).format( 'DD/MM/YYY ' ),
    amount: Number( val ) ? formatCurrency( str ) : val,
    details
 } );
console.ident =
    v => ( console.log( v ), v );

Function Composition

const userStr = localStorage.getItem( 'user' )
console.log( userStr )
// "[object Object]"

const userID = getUserId(
    JSON.parse( userStr )
);
// Uncaught SyntaxError: Unexpected token o in JSON at position 1

Function Composition

const user = JSON.parse(
    console.ident( localStorage.getItem( 'user' ) )
);

Ternary

console.log( val, Number( val ), !!Number( val ) );
// 0 0 false
Number( val ) ? formatCurrency( str ) : val;
// 0

Ternary

console.ident( Number( console.ident( val ) ) )
    ? formatCurrency( str )
    : val;

Object Construction, Return Expressions

const pickAndFormatTransaction = ( {
    description,
    date,
    amount,
    ...details
 } ) =>
    console.ident( {
        description,
        date: moment( console.ident( date )).format( 'DD/MM/YYY ' ),
        amount: console.ident( Number( val ))
            ? formatCurrency( str )
            : val
     } );

Chaining

const result = console
    .ident( arr.map( parseNumber s ).filter( removeOdds ) )
    .reduce( average );

Conclusion

console.ident = 
	v => ( console.log( v ), v );

Have Fun!