: 어떠한 조건을 판별하는 기준을 만드는 것, 반드시 비교연산자가 필요하다.
- ==, != 연산자는 있는데, 타입을 엄격하게 비교하지 못하기 떄문에 사용하지 않는게 좋다.
1 === 1 // true
1 === '1' // false - 타입이 다르기 때문이다
1 == '1' // true
1 == true // true
null == undefined // true
> 숫자의 비교
let age = 25;
console.log(19 < age) // true
let age = 17;
console.log(19 < age) // false
> 문자열의 비교
console.log('hello' === 'world') // false
console.log('hello' !== 'world') // true
> 숫자와 문자열의 비교
let str = '100';
let num = 100;
console.log( str === num); //false
> AND 연산자
console.log(false && true) // false
console.log(false && false) // false
> OR 연산자
console.log(false || true) // true
console.log(false || false) // false
> NOT 연산자
console.log(!true) // false
console.log(!false) // true
var str = 'codestates';
console.log(str[0]); // c
console.log(str[4]); // s
console.log(str[10]); // undefined
str[0] = 'G';
console.log(str) // 'codestates'가 나오지 , 'Godestates'가 안나옴
var str1 = 'code';
var str2 = 'states';
var str3 = '6';
console.log(str1 + str2); // 'codestates'
console.log(1 + str2); // '1states'
console.log(1 + str3); // '16'
var str = 'codestates';
console.log(str.length); // 10
> str.indexOf(searchValue-찾고자하는 문자열)
argument : 찾고자 하는 문자열
return value : 처음으로 일치하는 index, 찾고자 하는 문자열이 없으면 -1 // .indexOf 실행했을때 나오는 값
lastIndexOf는 문자열 뒤에서부터 찾음
'Blue whale'.indexOf('Blue'); // 0 -찾는 문자열이 어떤 인덱스에 있는지 가져옴(0번쨰 index부터 존재하니까)
'Blue whale'.indexOf('blue'); // -1 -찾는 문자열이 없어서
'Blue whale'.indexOf('whale'); // 5 -찾는 문자열이 어떤 인덱스에 있는지 가져옴(0번쨰 index부터 존재하니까)
'Blue whale whale'.indexOf('whale'); // 5 -만약 찾는 문자열이 중복되면 처음으로 일치하는 인덱스 위치로
'Blue whale'.includes('whale'); //true - 찾는 문자열이 없으면 false
'canal'.lastIndexOf('a') // 3 - 뒤에서 첫번째인 a의 인덱스 위치는 3임
> str.split(seperator)
argument : 분리 기준이 될 문자열
return value : 분리된 문자열이 포함된 배열
var str = 'Hello from the other side';
console.log(str.split(' ')); //공백을 이용해 잘라내어 ['Hello', 'from', 'the', 'other', 'side']
% csv형식 을 처리할 때 유용,, 파싱하기에 적합 -> csv 참고 https://ko.wikipedia.org/wiki/CSV_(%ED%8C%8C%EC%9D%BC_%ED%98%95%EC%8B%9D)
%% 파싱(parsing) : 어떤 페이지(문서, html 등)에서 내가 원하는 데이터를 특정 패턴이나 순서로 추출해 가공하는것을 말한다.
ex) let dsw = `연도,제조사,모델,설명,가격
1997,Ford,E350,"ac, abs, moon",3000.00
1999,Chevy,"Venture ""Extended Edition""","",4900.00
1999,Chevy,"Venture ""Extended Edition, Very Large""",,5000.00
1996,Jeep,Grand Cherokee,"MUST SELL!air, moon roof, loaded",4799.00` // undefined
- dsw.split('\n') 줄바꿈으로 한줄씩 분석가능
// (5) ['연도,제조사,모델,설명,가격', '1997,Ford,E350,"ac, abs, moon",3000.00', '1999,Chevy,"Venture ""Extended Edition""","",4900.00', '1999,Chevy,"Venture ""Extended Edition, Very Large""",,5000.00', '1996,Jeep,Grand Cherokee,"MUST SELL!air, moon roof, loaded",4799.00']
- dsw.split(',')
// (26) ['연도', '제조사', '모델', '설명', '가격\n1997', 'Ford', 'E350', '"ac', ' abs', ' moon"', '3000.00\n1999', 'Chevy', '"Venture ""Extended Edition"""', '""', '4900.00\n1999', 'Chevy', '"Venture ""Extended Edition', ' Very Large"""', '', '5000.00\n1996', 'Jeep', 'Grand Cherokee', '"MUST SELL!air', ' moon roof', ' loaded"', '4799.00']
let lines = dsw.split('\n')
lines[0] // '연도,제조사,모델,설명,가격'
lines[0].split(',') // (5) ['연도', '제조사', '모델', '설명', '가격']
> str.substring(start, end) + .slice 와 비슷(동일한건 아님)
argument : 시작 index, 끝 index (순서 바뀌어도됨)
return value : 시작과 끝 index사이의 문자열
var str = 'abcdefghij';
console.log(str.substring(0,3)); // 'abc' ->3인덱스의 앞까지만 나옴 'd'가 str[3]이긴 하지만,앞까지만임
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, 23)); // 'abcdefghij' 범위초과시 마지막까지만 나옴
> str.toLowercase() /str.toUppercase() ***IMMUTABLE -원본이 변하지 않음 *** string의 method는 모두 IMMUTABLE( 이뮤터블한 값을 바꾸고 싶으면 새로 대입해야함)<-> 반대말은 mutable ( array method는 IMMUTABLE, mutable여부를 잘 기억해야 함!!)
argument : 없음
return value : 대, 소문자로 변환된 문자열
console.log('ALPHABET'.toLowerCase())' // 'alphabet'
console.log('alphabet'.toUpperCase())' // 'ALPHABET'
ex) let word = 'hello';
word.toUpperCase() // 'HELLO'...여기서! 그럼 word는 대문자 HELLO냐, 소문자 hello냐..
word // 'hello' 로 소문자가 나옴!!
function makeLastSeenMsg(name, period) {
let num1 = parseInt(period)
if( //....
}else if(1 <= (num1/1440) && (num1/1440) < 31){ ....//
-> 마지막 조건 부분이 해결되지 않았는데, 원래는 ' 1 <= (num1/1440)< 31 '이렇게 써서 안됬었다. 부등호 조건 전체가 or이 적용되는지, and인지 확인할수 없어서 조건 제대로 만족 할수 없기때문에 생각한데로 나오지 않는다