let bool = true
// with function
function toggle () {
// long way
if(bool){
bool = false
} else {
bool = true
}
// short way
bool = !bool
}
// inline way 1
bool = bool ? false : true
// inline way 2
bool = !bool
state.map((todo, index) => (index === action.index) ? {...todo, completed: !todo.completed} : todo)
let flag = false;
const toggle = () => {
if ( flag ) {
// insert code here when flag is on/true
} else {
// insert code here when flag is off/false
}
flag = ! flag;
}