2. 자바스크립트 타입변환
2024. 11. 1. 16:35ㆍ자바스크립트(Javascript)
1. 데이터 타입
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>2.데이터타입</title>
</head>
<body>
<script>
// number 형
const num1 = 10;
const num2 = 11.11;
//10의 6승
const num3 = 10e6;
console.log(num1); //10
console.log(num2); //11
console.log(num3); //10000000
console.log(typeof(num1)); //number
console.log(typeof(num2)); //number
console.log(typeof(num3)); //number
console.log('-------------');
//string 형
const str1 = 'Hello'
const str2 = 'Javascript'
const str3 = '10'
console.log(typeof(str1)) //string
console.log(num1 + num2) //21.11
console.log(str1 + str2) //HelloJavascript
console.log(str1 + " " + str2) //Hello Javascript
console.log(`${str1} ${str2}`) //Hello Javascript
console.log(`자바스크립트에서는 문자열을
큰따옴표 또는 작은 따옴표로 저장한다`)
//const num1 = 10; const str3 = '10'
console.log(num1 + str1) //10Hello
console.log(num1 - str3) //0
console.log(num1 * str3) //100
console.log(num1 / str3) //1
console.log(`-------------`)
//boolean
const b1 = true;
const b2 = false;
console.log(typeof(b1)) //boolean
console.log(10 > 5) //true
console.log(`-------------`)
// undefined
let num
console.log(num) //undefined
console.log(typeof(num)) //undefined
console.log(`-------------`)
//null
let obj1 = {}
console.log(obj1) //Object
console.log(typeof(obj1)) //object
let obj2 = null
console.log(typeof(obj2)) //object
</script>
</body>
</html>
728x90
LIST
'자바스크립트(Javascript)' 카테고리의 다른 글
6. 조건문 - switch문 (0) | 2024.11.01 |
---|---|
5. 조건문 - if문 (0) | 2024.11.01 |
4. 대화상자 (0) | 2024.11.01 |
3. 타입변환 (0) | 2024.11.01 |
1. 자바스크립트(Javascript) (14) | 2024.11.01 |