Because you are storing the old $('body > p') element on a variable, and printing the same result two times.
let length = $('body > p').length;
console.log(length);
Stores the length of the current 'body > p', it dosent exists, then is 0.
$('body').append($('<p>').text('plain text'));
console.log(length);
You append the new element, but you are printing the OLD element length value, so you get 0 again, you need to "refresh" the element.
Something like this:
let length = $('body > p').length;
console.log(length);
$('body').append($('<p>').text('plain text'));
length = $('body > p').length;
console.log(length);
setTimeout(() => console.log(length), 1000)
Using jQuery when you do something like this:
var element = $('element');
You are generating an "snapshot" of the element, it means the element is stored on the variable on the moment you declare it. If the element changes but you dont refresh the variable it will return the same values like when you declared it.
lengthin cache..lengthwill return a number which will not automatically change after adding newpelement. Use$('body > p').lengtheach time to get updated no. ofpelements.