커뮤니티
포인트
쿠폰
내 강의실
국비 신청 내역
증명서
계정
로그아웃
학습 질문
개발 일지
나의 활동
답변 완료
변수 활용 범위
undefined주차
북마크
배*익
댓글
5
추천
0
조회수
12
조회수
12
답변 완료

        $(document).ready(function () {


            let degree


            fetch("http://spartacodingclub.shop/sparta_api/weather/seoul").then(res => res.json()).then(data => {

                degree = data['temp']

                console.log("1: " + degree)


                $('#temp').text(degree)

            })

            console.log("2: " + degree)

        })


degree 변수가 살아있는 범위가 어디인가요? 저는 1: 15.67, 2: 15.67 이라고 나와야 된다고 생각하는데, 2:에는 null 값이 들어가는 것처럼 보이네요.


저는 degree를 $(document).ready(function () 함수 내에 선언했기 때문에, degree를 $(document).ready(function () 내에서 메모리에 살아있다고 생각했습니다. 그런데 콘솔에 찍어보면, 아래 처럼 나오네요.


2: undefined

1: 15.67

취소
 공유
취소
댓글 0
댓글 알림
나의얼굴