Can you please help me run this code with way ı want [duplicate]

hi everyone ı am trying to do something like that you see down. What ı want is if next sibling of H1 is H4 element then log to console “right” but without defining H4 element javascript dont understand.Also when ı tried ı get this error –>Cannot set property nextSibling of # which has only a getter at script.js:219:18

if(h1.nextSibling=h4){
  console.log('right');
}

and ı also tried this

if(h1.closest=h4){
  console.log('right');
}

this last code worked but ı had to define h4 which is what ı dont want to
but when ı deleted already selected variable (const h4=document.querySelector(‘h4’)) it’s again started say h4 undefined. right now what ı want is find a way to run this code without speacially define h4
please help me