강의

멘토링

커뮤니티

Inflearn Community Q&A

minju58320531's profile image
minju58320531

asked

[Renewal] Introduction to JavaScript in Zero Seconds through Coding Self-Study

Calculate results, initialize

쿵쿵따, 계산기에서 변수 선언

Written on

·

166

0

안녕하세요 변수 선언 관련해 질문이 있습니다

 

쿵쿵따에서는 단어 저장할 변수를 만들 때 아래와 같이 변수자체만 선언하고

계산기 만들기를 할 때는 숫자랑 연산자 저장할 변수를 만들 때 아래처럼 빈 문자열을 넣는데 어떤 이유가 있는 건지 궁금합니다

계산기 만들기에서 아래처럼 선언하면 숫자가 저장되지 않고 NaN이 나오더라구요

javascript

Answer 1

0

zerocho님의 프로필 이미지
zerocho
Instructor

''가 선언되어 있어야 +를 할 때 문자열이 저장됩니다.

'' + 5 === '5';

그게 없으면 undefined라서

undefined + 5 === NaN

minju58320531's profile image
minju58320531

asked

Ask a question