D3: 조건문, 반복문, 함수

devfish·2022년 12월 19일
0

Javascript

목록 보기
3/30

SUMMARY

  • typeof: returns a string
    typeof 42, typeof 'hello', typeof true, typeof undeclaredVariable
  • template literal can..
    • include functions/operations
    • print out function declarations/expressions!
  • you declare a function with...
    • keyword ("function"), function name, parameters, code block to execute, return value
  • function expressions: different way of declaring/expressing a function
  • careful with while loops that do not specify an end point at which the loop should end (infinite loops)
  • >= || <= (o) ; => (x)
  • 동치연산자 (===, ==, !==, !=), 할당연산자 (=)
  • you can include an operation (e.g. a * b) inside a template literal!
    • console.log(`${num} x ${i} = ${num * i}`);

삼항연산자

  • a ? b : c
  •   let num = 5;
      num % 2 === 0 ? console.log('짝수') : console.log('홀수'); // '홀수입니다.'

for-loop vs. while-loop

  • while loop: when you're not sure how many times to repeat
  • for loop:
    • when you're relatively sure of what you want to repeat
    • when you are going through a string or array
    • when you need nested for-loops
  • know how to transform one into the other

for loop

  • for (초기값; 조건식; 증감식) { // 실행할 코드 }
  • index: str[num]; str.indexOf('a')
  • you can nest as many for loops within a for loop!

while loop

  • careful of infinite loops - check if the condition becomes false at a certain point
  • do...while -> do is done at least once before evaluating the while condition

functions

  • keyword (function) / name / parameter(s) (매개변수)
  • you call/invoke (호출) a function with arguments (전달인자 - assigned values to parameters when calling a function), which returns a result
  • 함수선언문 (function declaration) vs. 함수표현식 (function expression)
    - you can print a function (not the return value, but actual function declaration/expression) inside a template literal!
  • scope: parameter names only work within the scope of the function
  • you can assign the returned value of a called function into a variable
profile
la, di, lah

0개의 댓글