There is a structure:
If you run code 1:
var ul = document.getElementById('demo');
var liList = ul.getElementsByTagName('li');
for (var i = 0; i < = liList.length; i ) {
ul. removeChild(liList[i]);
}
If you were deceived like me, then you will understand the reason after looking at the correct code!
var ul = document.getElementById('demo');
var liList = ul.getElementsByTagName('li');
var lilength = liList.length;
for (var i = 0; i < lilength; i ) {
ul.removeChild( liList[0]);
}