Fundamentals Part 2

sun·2021년 9월 4일

자바스크립트의 자료형 8가지는?

  • number
  • bigint : ±(2^53-1) 보다 크거나 작은 숫자를 위한 자료형
  • string
  • boolean
  • null : 모르는 값
  • undefined : 지정하지 않은 값
  • object : 원시 타입보다 복잡한 자료 구조를 위한 자료형으로 참조 타입이라고도 부름
    cf. 객체 자료형 외의 자료형은 모두 원시 타입
  • symbols : 객체에 고유한 id를 부여하는 데 사용

null 과 undefined

  • null 과 undefined 는 sweet couplenull == undefined 의 관계가 성립
    cf. null === undefined 의 경우에는 형변환이 이루어지지 않으므로 거짓
  • < > <= >= 비교 연산의 경우 null0으로 형변환, undefinedNaN으로 형 변환

string에서   ''   ""   `` 의 차이는?

  • 앞의 두 가지는 동일한 역할로 통상적인 문자열을 나타내는 데 사용
  • `` 의 경우 let str = `today is ${day}.` 와 같이 템플릿 리터럴을 나타내는 데 사용

메서드란?

  • 객체에 수행할 수 있는 동작
  • 함수를 내포하고 있는 프로퍼티

slice, substring, substr의 차이는?

>>> let txt = "apple is my favorite fruit.";
// SLICE
>>> txt.slice(6, 8)
is
>>> txt.slice(-14, -6);
favorite

//SUBSTRING
>>> txt.substring(6, 8)
is
>>> txt.substring(-14, -6)
""

//SUBSTR
>>> txt.substr(6, 2)
is
>>> txt.substr(-14, 8)
fruit

논리 연산자 3가지는?

  • || OR : 최초의 참인 피연산자 혹은 모두 거짓인 경우 마지막 피연산자 반환
  • && AND : 최초의 거짓인 피연산자 혹은 모두 참인 경우 마지막 피연산자 반환
  • ! NOT : 해당 피연산자를 불린형으로 형변환한 뒤 반대 값을 반환
  • 우선순위 : ! > && > ||

비교 연산자란?

  • > < >= <= == === != !==
  • 불린 결과값을 반환
  • 문자열 비교는 사전편찬식으로 이루어짐
  • 서로 다른 타입 간의 비교는 숫자로의 형변환을 통해 이루어짐(===, !== 제외)
  • null : > < >= <= 비교 시 0으로 변환,
                  == 동등 연산 시 undefined 랑만 동등
  • undefined : > < >= <= 비교 시 NaN으로 변환,
                            == 동등 연산 시 null 이랑만 동등

truthy 와 falsy 값이란?

  • truthy : true로 평가되는 값
  • falsy : false로 평가되는 값
    e.g. false, 0, -0, null, ''/""(empty string), undefined, Nan

조건문이란?

  • 선택(조건)에 따라 다른 결과를 나타낼 수 있도록 하는 형태의 구문

if-else 조건문의 형태는?

if (condition) {
  // code to run when condition is true
} else {
  // code to run when condition is false
}

switch문의 형태는?

switch (expression) {
  case value1:
    // code to run when result of expression matches value1
    break;
  case value2:
    // code to run when result of expression matches value2
    break;
  ...
  case valueN:
    // code to run when result of expression matches valueN
    break;
  default:
    // code to run when result of expression matches none of the values
}

삼항연산자 구문의 형태는?

let variable = (condition) ? value when condition is true : value when condition is false;

nesting이란?

  • 함수/조건문 안에 함수/조건문을 중첩해서 사용하는 것
    if (condition) {
      // some code 
    } else {
        if (condition) {
          // this is nesting
          // some code
        } else {
            //some code
        }
    }
profile
☀️

0개의 댓글