'Is nesting possible in Javascript?

For the first time ever in my lessons, I saw a completely different way of writing javascript code:

let parentClicks = 0;
let childClicks = 0;

document
  .getElementById("parent")
  .addEventListener("click", function() {
  document
    .getElementById("parent-count")
    .innerText = (++parentClicks) + '';
});

document
  .getElementById("child")
  .addEventListener("click", function(e) {
  e.preventDefault();
  e.stopPropagation();
  
  document
    .getElementById("child-count")
    .innerText = (++childClicks) + '';
});

I was used to seeing nesting on HTML/CSS, but it's the first time ever I see it on JS.

Do these points mean this or they have a complete different meaning?

document.getElementById("parent")
document.addEventListener("click", function() {
  document.getElementById("parent-count")
  document.innerText = (++parentClicks) + '';
});

document.getElementById("child")
document.addEventListener("click", function(e) {
  e.preventDefault();
  e.stopPropagation();
  
  document.getElementById("child-count")
  document.innerText = (++childClicks) + '';
});


Solution 1:[1]

The indentation looks off in your first example. A few editor might throw error for this. It's always best to use period together in such scenarios. For ex- document. and not document .

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 techie_questie