Last active
May 3, 2016 16:49
-
-
Save jjsub/b631311a3b424e1ea26b59a08df12e1c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Good practice to verify if a var exist or not or is the value is the one expected | |
var x = 0; | |
if ( typeof x !== 'undefined') { | |
console.log('Exist'); | |
} else { | |
console.log('Not exist'); | |
} | |
// Redux | |
function counter(state, action) { | |
if (typeof state === 'undefine') { | |
return 0; | |
} | |
if (action.type === 'INCREMENT') { | |
return state + 1 | |
} else if(action.type === 'DECREMENT') { | |
return state - 1; | |
} else { | |
return state; | |
} | |
} | |
//Redux - ES6 | |
const counter = (state = 0, action) => { | |
switch (action.type) { | |
case 'INCREMENT': | |
return state + 1; | |
case 'DECREMET': | |
return state - 1; | |
default: | |
return state; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment