I wrote the following, I dont understand why its working in this case:
function newTodo() {
let list = $('#input').val();
$('#todo-list').append($("<li><input type='checkbox'><label>" + list + "</label>" + "</li>"));
}
list = $('#input').val('');
However when I put the variable outside of the function like so:
let list = $('#input').val();
function newTodo() {
$('#todo-list').append($("<li><input type='checkbox'><label>" + list + "</label>" + "</li>"));
}
list = $('#input').val('');
All I get is Object Object, when I am expecting a string. Why is this?