请问这两种情况是因为形成了闭包吗?

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let arr = []
        for (let i = 0; i < 5; i++) {
            arr.push(function () {
                console.log(i);
            })
        }
        let i = 10;
        arr[0]() //0


        let fn; 
        {
            let n = 0;
            fn = () => {
                console.log(n);
            }
        }
        let n = 10;
        fn() //0
    </script>
</body>

</html>

 

鄙人拙见这都是this指向问题:

第一个问题,arr[0]() //0  arr[1]() //1 没毛病
第二个问题,箭头函数没有this,console.log (n),会找上级环境的n,上级环境是 这个对象,对象是的 n是 0,你的n= 10 是在最外层 window 下。所以=0

点不点赞都无所谓的~,

闭包的概念了解一下。同意楼上观点。确实是this指向问题。https://blog.csdn.net/qq_28387069/article/details/83120034