I want to understand this please, someone can write as (if/else/elseif) statments ???
lists[list === 'todo' ? 'done' : 'todo'].appendChild(task);
Thanks
I want to understand this please, someone can write as (if/else/elseif) statments ???
lists[list === 'todo' ? 'done' : 'todo'].appendChild(task);
Thanks
You can rewrite it as:
if (list === 'todo') {
lists.done.appendChild(task);
}
else {
lists.todo.appendChild(task);
}
The thing here is that you can access any property of the object via bracket notation, which allows variables and expressions resolving to a property name. Thus, lists.done
is equivalent to lists['done']
but with the later you can use expressions to calculate key name. This is what you have in the original example.
if (list === 'todo') {
lists['done'].appendChild(task);
else {
lists['todo'].appendChild(task);
}