[๐ŸŒณJavascript] ์ž๋ฃŒํ˜•

h-a-n-aยท2023๋…„ 1์›” 25์ผ
1

๐ŸŒณjavascript

๋ชฉ๋ก ๋ณด๊ธฐ
4/17

์ž๋ฃŒํ˜•

์›์‹œํ˜•

์ˆซ์žํ˜•

  • ์ •์ˆ˜ ๋ฐ ๋ถ€๋™์†Œ์ˆ˜์  ์ˆซ์ž
  • NaN: Not a Number

๋ฌธ์žํ˜•

"", '', ``์œผ๋กœ ํ‘œํ˜„ ๊ฐ€๋Šฅ

๋ถˆ๋ฆฐ

null

๋ช…์‹œ์ ์œผ๋กœ, ์˜๋„์ ์œผ๋กœ ๊ฐ’์ด ์—†์Œ์„ ๋งํ•จ

undefined

symbol

BigInt

๊ธธ์ด ์ œํ•œ์ด ์—†๋Š” ์ •์ˆ˜

์ฐธ์กฐํ˜•

๋ฐฐ์—ด

๋ฐฐ์—ด์˜ ์•„์ดํ…œ, ์š”์†Œ๋ผ๊ณ  ๋ถ€๋ฆ„

๊ฐ์ฒด

๊ฐ์ฒด์˜ ๋ฉค๋ฒ„(์†์„ฑ๊ณผ ๋ฉ”์†Œ๋“œ)์— ์ ‘๊ทผํ•  ๋•Œ์—๋Š” ์  ํ‘œ๊ธฐ๋ฒ•๊ณผ ๋Œ€๊ด„ํ˜ธ ํ‘œ๊ธฐ๋ฒ•์„ ํ†ตํ•ด ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋‹ค.

const Tiffany = {
  "name": "jiwoo",
  "age": 28,
}
const Hana = {
  "name": "hyewon",
  "age": 27,
  "friend": Tiffany // ์œ„์—์„œ ์‚ฌ์šฉํ•œ ๋ณ€์ˆ˜์ด๋ฏ€๋กœ ""์•ˆ์— ์“ฐ์ง€ ์•Š๊ธฐ
}
console.log(Hana.name)//'hyewon'
console.log(Hana["name"])//'hyewon'
//์ฒด์ด๋‹ ๊ฐ€๋Šฅ
console.log(Hana.friend.name) //'jiwoo'
console.log(Hana["friend"]["name"])//'jiwoo'

delete Hana.age // ์†์„ฑ ์‚ญ์ œ

ํ•จ์ˆ˜

์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์—์„œ ํ•จ์ˆ˜๋Š” 1๊ธ‰ ๊ฐ์ฒด๋กœ, ํ•˜๋‚˜์˜ ๊ฐ’์ด๋‹ค.
๋ณ€์ˆ˜/์ธ์ˆ˜ ๊ฐ€๋Šฅํ•˜๊ณ , ๋ฐ˜ํ™˜์ด ๊ฐ€๋Šฅํ•˜๋‹ค(return ๊ฐ’ ์•ˆ ์“ฐ๋ฉด undefined)

a() // a
b() // Uncaught ReferenceError: b is not defined
//ํ•จ์ˆ˜์„ ์–ธ -> ํ˜ธ์ด์ŠคํŒ…์— ์˜ํ–ฅ์„ ๋ฐ›์Œ
function a(){
	console.log("a")
}
//ํ•จ์ˆ˜ํ‘œํ˜„ -> ํ˜ธ์ด์ŠคํŒ…์— ์˜ํ–ฅ ๋ฐ›์ง€ ์•Š๋Š”๋‹ค
const b = function (){
	console.log("b")}

Truthy vs Falsy

truthy

falsy 8๊ฐœ ์ œ์™ธํ•œ ๋ชจ~~๋“  ๊ฒƒ
1, 123, [](๋นˆ ๋ฐฐ์—ด), {}(๋นˆ ๊ฐ์ฒด), function, ....

falsy

๋”ฑ 8๊ฐœ! false, null, undefined, bigint, 0,-0,NaN,""(๋นˆ ๋ฌธ์ž์—ด)

ํ˜• ๋ณ€ํ™˜(type conversion)

== ๋™๋“ฑ์—ฐ์‚ฐ์ž

๋‘ ์—ฐ์‚ฐ์ž์˜ ๊ฐ’์ด ์„œ๋กœ ๊ฐ™์œผ๋ฉด true๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค.
ํƒ€์ž…์ด ๋‹ค๋ฅผ ๊ฒฝ์šฐ, ๋น„๊ต๋ฅผ ์œ„ํ•ด ๊ฐ•์ œ์ ์œผ๋กœ ํ˜• ๋ณ€ํ™˜์ด ์ผ์–ด๋‚จ

const a = 1
const b = '1'
console.log(a == b) //true
0 == false // true
1 == true // true

=== ์ผ์น˜์—ฐ์‚ฐ์ž

ํ˜•(type)๊ณผ ๊ฐ’ ๋ชจ๋‘ ์ผ์น˜ํ•ด์•ผ ํ•จ

1 === '1' //false
1 === 1 //true
0 === false // false

์ž๋ฃŒํ˜• ํ™•์ธ

typeof

typeof "1" //string
typeof 1//number
typeof true//boolean
typeof null//object
typeof undefined // undefined
typeof symbol //symbol
typeof 123n // bigint
typeof [array] // object
typeof {object} //object
typeof function(){} // function
// Object.prototype.toString.call(DATA) 
// '[object TYPE]'
function checkType(d) {
  return Object.prototype.toString.call(d).slice(8, -1)
}
console.log(checkType(data.string)) // 'String'
console.log(checkType(data.number)) // 'Number'
console.log(checkType(data.boolean)) // 'Boolean'
console.log(checkType(data.null)) // 'Null'
console.log(checkType(data.undefined)) // 'Undefined'
console.log(checkType(data.symbol)) // 'Symbol'
console.log(checkType(data.bigint)) // 'BigInt'
console.log(checkType(data.array)) // 'Array'
console.log(checkType(data.object)) // 'Object'
console.log(checkType(data.function)) // 'Function'
profile
ํ•˜๋ฃจํ•˜๋ฃจ๊ฐ€ ์—ฐ์Šต์ด๋‹ˆ ๋‚ด์ผ์€ ๋” ๊ฐ•ํ•ด์งˆ ๊ฒ๋‹ˆ๋‹ค

0๊ฐœ์˜ ๋Œ“๊ธ€