0

Works when creating 2 variables:

var val;

var list = document.querySelector('.list-group');

val = list;


val = list.childNodes;

console.log(val);
    <ul class="list-group">
        <li>1</li>
        <li>2</li>
    </ul>

1 variable does not work:

var list = document.querySelector('.list-group');


list.childNodes;

console.log(val); 
     <ul class="list-group">
        <li>1</li>
        <li>2</li>
    </ul>

Doesn't work in firefox and chrome console with let variable:

let val;

let list = document.querySelector('.list-group');

val = list;


val = list.childNodes;

console.log(val);
    <ul class="list-group">
        <li>1</li>
        <li>2</li>
    </ul>

enter image description here

works with the same operations on Udemy video and StackOverflow

enter image description here

What are the differences between? Why firefox does not work with the let variable?

KarthikNayak98
  • 363
  • 3
  • 13
000
  • 11
  • 10
  • Your second snippet doesn't work because you've never declared a variable named `val`. If you wanted a single variable with the `childNodes`, then do `document.querySelector('.list-group').childNodes` – CertainPerformance Feb 11 '21 at 04:56
  • Your second piece of code does nothing because you `console.log(val)` but you never assigned it. Try `console.log(list)`. Your third piece of code works fine on firefox; your issue is that you have already declared `val` and so can't redeclare it – Nick Feb 11 '21 at 04:56

0 Answers0