자바스크립트 변수_js

2021. 12. 16. 09:22ksmart_html_css_js/JavaScript

728x90

- 메모리 공간을 만들어 데이터를 저장하는 것

- 변수 선언은 var(동일한 변수 허용)나 let(동일한 변수 허용x) 키워드로 선언한다.

- 자료형은 값에 의해 결정이 된다.

- 자료형에 기본형은 문자형, 숫자형, 논리형이 있다.

-자료형을 확인하는 키워드는 typeof 키워드 이다.

- 자바스크립트의 변수 기본값은 undefined 이다.

- 변수명(식별자)에는 예약어를 사용할 수 없다.

예약어 -> 프로그램에서 사용하고 있는 키워드(토큰)

var return =''; 사용 불가

- 변수명에는 숫자가 처음에 나올 수 없다

- 변수명에는 특수기호는 사용 할 수 없다.(단 $, _기호 사용 가능)

- 상수는 const 라는 키워드로 선언한다.

var
변수 선언 키워드
str01
변수명(식별자)
=
대입 연산자
결과
str01 변수를 만들고 (메모리 생성) 값을 ''(공백) 삽입
var str01='';

- 좌 결과 = 우 : 연산

 

문자형_문자형은 '' 나"" 로 시작하고 닫는다

var str01='홍길동';		
console.log(str01,typeof str01);

var str02="이순신";		
console.log(str02,typeof str02);

var str03='"'';		
console.log(str03,typeof str03);
​

 

숫자형
var num01=10;
console.log(num01, typeof num01);

논리형
var bool01=false;
console.log(bool01, typeof bool01);

- 변수 선언 이후 목적에 맞는 값이 삽입될 수 있도록 한다.

 

기본값 undefined
var unde01;
console.log(unde01, typeof unde01);

 

null -> 변수와 연결된 객체를 연결 해제 할 때
var null01=null;
console.log(null01, typeof null01);

예약어 테스트 - 변수명으로 사용 불가능
var if=0;
var return=10;

 

상수
const con01='홍길동';
console.log(con01, typeof con01);

const con01='홍길동';
console.log(con01, typeof con01);
const con01='이순신';

728x90

'ksmart_html_css_js > JavaScript' 카테고리의 다른 글

연산자2_js  (0) 2021.12.16
연산자_js  (0) 2021.12.16
변수 표기법_js  (0) 2021.12.16
Let, Var_js  (0) 2021.12.16
자바 스크립트 시작하기_js  (0) 2021.12.16