201027_TIL

Eric Kim·2020년 11월 2일
0

비교 연산자

> 초과
< 미만
>= 이상
<= 이하
=== 같다
!== 다르다

조건문

if (조건1) {
  //조건1이 통과할 경우
} else if (조건2) {
  //조건1이 통과하지 않고
  //조건2가 통과할 경우
} else {
  //모든 조건이 통과하지 않는 경우

AND 연산자 OR 연산자 NOT 연산자

isStudent && isFemale; //학생이면서, 여자일 때 통과
isStudent || isFemale; //학생이거나, 여자일 때 통과
!isStudent && isFemale; //학생이 아니면서, 여자일 때 통과

기억해야 할 6가지 falsy 값

if (false)
if (null)
if (undefined)
if (0)
if (NaN)
if ('')

Achievement Goals

  • truthy와 falsy 가 조건문에서 작동하는 방식을 이해할 수 있다.
  • 논리 연산자에 대해 이해할 수 있다.
  • if 와 else if , else를 이해하고 무리없이 활용할 수 있다.
  • 복잡한 조건문을 활용하여 실생활에서 쉽게 마주할 수 있는 문제를 해결할 알고리즘을 짤 수 있다.

length PROPERTY

let str = 'CodeStates';
console.log (str.length)l // 10 글자수

ACCESSING A CHARACTER

let str = 'CodeStates';
console.log(str[0]); // 'C'
console.log(str[4]); // 'S'
console.log(str[10]); // 'undefined'

CONCATENATING STRINGS

let str1 = 'Code';
let str2 = 'States';
let str3 = '1'
console.log (str1 + str2); // 'CodeStates'
console.log (str3 + 7); // '17'

str.indexOf (searchValue)

'Blue Whale'.indexOf ('Blue'); // 0
'Blue Whale'.indexOf ('blue'); // -1
'Blue Whale'.indexOf ('Whale'); // 5
'Blue Whale Whale'.indexOf ('Whale'); // 5

'canal'.lastIndexOf ('a'); // 3

str.substring (start, end)

let str = 'abcdefghij';
console.log (str.substring (0, 3)); // 'abc'
console.log (str.substring (3, 0)); // 'abc'
console.log (str.substring (1, 4)); // 'bcd'
console.log (str.substring (-1, 4)); // 'abcd', 음수는 0으로 취급
console.log (str.substring (0, 20)); // 'abcdefghij', index 범위를 초과하면 마지막까지

str.toLowerCase() / str.toUpperCase()

console.log ('ALPHABET'.toLowerCase()); // 'alphabet'
console.log ('alphabet'.toUpperCase()); // 'ALPHABET'

str.split (separator)

let str = 'Hello from the other side'
console.log (str.split(' ')); 
// ['Hello', 'from', 'the', 'other', 'side']

Achievement Goals

  • 문자열의 속성과 메소드를 이용해 원하는 형태로 만들 수 있다.
  • 문자열의 length라는 속성을 활용해 길이를 확인할 수 있다. str.length
  • 문자열의 글자 하나하나에 접근할 수 있다. str[1]
  • 문자열을 합칠 수 있다. word1 + " " + word2
  • 문자열을 원하는 만큼만 잡을 수 있다. str.substring(0, 3)
  • 영문을 모두 대문자로 바꿀 수 있다. str.toUpperCase
  • 문자열 중 원하는 글자의 index를 찾을 수 있다 str.indexOf('a')
  • 문자열 중 원하는 글자가 포함되어 있는지 알 수 있다. str.includes('a')
profile
newbieForNow

0개의 댓글