Js scopes how to figure it out?

  • 0
    let arr = [];
    
    function mapMap(value,key,map){
        if(key.indexOf(substrcon)+1){
            arr.push(key);
        }
    
        console.log(arr)
    
    }

    1 example

    why doesn't it work ?? I thought mb in the if creates some kind of scope and this is the point
    BUT
    I created a similar simplified example with exactly the same scope and it works

    let arr=[];
    
    function xxl(){
    
      for(let i=0; i<10; i++){
        if(i%2==0){
        arr.push(i)}
      }
    }
    JavaScript Penelope Church, Apr 3, 2019

  • 0 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!