1 - 4 Dynamic typing

👩‍💻NEO_매트릭스·2022년 1월 21일
0

JAVA

목록 보기
4/11

1 - 4 Dynamic typing : dynamically typed language

let text = 'hello'; //type이 string이됨.

console.log(`value: ${text}, type: ${typeof text}`);

text = 1;  //type이 number가 됨

console.log(`value: ${text}, type: ${typeof text}`);

//string '7'과 number 5를 더해버리면, 자바스크림트 엔진이 5를 string으로 변환해줌

text = '7' + 5;

console.log(`value: ${text}, type: ${typeof text}`);

//string과 string을 나누면 안에 숫자를 인식하고 number로 변환 나누어줌.

text = '8' / '2';

console.log(`value: ${text}, type: ${typeof text}`);

🚨 여기서 주의 🚨

let text = 'hello'; 
console.log(text.charAt(0)); //첫번째 문자 보여줘
console.log(`value: ${text}, type: ${typeof text}`);

//string과 string을 나누면 안에 숫자를 인식하고 number로 변환 나누어줌.
text = '8' / '2';
console.log(`value: ${text}, type: ${typeof text}`);

console.log(text.charAt(0)); 
// 첫번째 문자 보여줘 안보여짐, number로 변경된상태;

다이나믹 타이핑 문제를 타입스크립트로 해결이 가능.

TS의 등장! 자바스크립트에 타입이 얹어진 언어이다.

JavaScript와 TypeScript

  • TypeScript는 JavaScript 기반의 언어
  • JavaScript는 클라이언트 측 스크립팅 언어 TypeScript는 객체 지향 컴파일 언어
  • 객체 지향 프로그래밍 패러다임은 데이터 추상화에 중심객체와 클래스라는 두 주요 개념을 기반으로 함

0개의 댓글