웅돌이
2020. 3. 5. 17:53
'use strict'
let string = 'node.js 올인원 패키지';
let isStartWith = string.startsWith('n');
//let isIncludes = string.includes('올인원');
let isIncludes = string.includes(',');
let isEndWith = string.endsWith('지');
const checkIfContains = () => {
if (isStartWith && isIncludes && isEndWith) {
return true
} else {
return false
}
}
const ret = checkIfContains();
console.log(ret);
자바스크립트는 기본적으로 string에 대해 유니코드 사용이 가능하고, 다른 언어(자바 등)에 비해 string 객체에 대한 표현이 자유로운 편이다.
string객체에 대한 내장함수로는 startsWith, includes, endsWith, length등이 있고 기능은 위에서 보듯이 함수명과 일치한다
&&, || 등의 비교연산자는 타입을 체크할 때 특별히 순서의 정함이 없이 체크가 된다. 따라서 특정조건(||와 &&를 섞어 쓸 경우)을 적용하고 싶을때는 () 를 이용하여 셈의 우선순위를 정하듯이 조건의 우선체크순위를 정해주는 것이 좋다.