Skip to content

Instantly share code, notes, and snippets.

@jjsub
Last active May 3, 2016 16:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jjsub/b631311a3b424e1ea26b59a08df12e1c to your computer and use it in GitHub Desktop.
Save jjsub/b631311a3b424e1ea26b59a08df12e1c to your computer and use it in GitHub Desktop.
// 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