почему return не возвращает значение константы?
Не понимаю почему return не возвращает значение локальной newItem наружу в addToList().
function createElements(value) {
const newItem = document.createElement('li');
newItem.textContent = `${value}`;
const trashIcon = document.createElement('div');
trashIcon.classList.add('delete');
return newItem;
}
function addToList(value) {
list.prepend(newItemCopy);
newItem.append(trashIcon);
console.log(todoDB);
}
Ответы (1 шт):
Автор решения: Igor
→ Ссылка
Чтобы функция createElements что-то куда-то возвращала, ее надо, по крайней мере, вызвать.
function createElements(value) {
const newItem = document.createElement('li');
newItem.textContent = `${value}`;
const trashIcon = document.createElement('div');
trashIcon.classList.add('delete');
newItem.append(trashIcon);
return newItem;
}
function addToList(value) {
...
const newItem = createElements(value);
...
}
P.S. Переменные, объявленные внутри функции, не видны снаружи.