WHAT I LEARNED
While my partner and I solve problems together, sometimes I realize that we both need to think simply because we tend to overthink. Fortunately, we get along and I am thankful for my buddy who always answers the questions I ask and help me review what I have learned. I think we can finish what we have to do according to the timeline.
- CONDITIONAL(조건문)
- Always need 'Comparison Operator'(비교 연산자)
- > more than
- < less than
- >= ane more
- <= and less
- === equal
- !== not equal
- Result is always 'boolean'(true/false)
1234if(condition 1) {} else if (condition 2) {} else {}
c - else can be omitted depends on function.
- To apply 2 conditions together, use 'Logical Operator'(논리 연산자)
- AND: &&
123true && true // truetrue && false // falsefalse && false //false
cs - OR: ||
123true || true // truetrue || false // truefalse || false //false
cs - NOT: ! (falsy) **memorize
123456if (false)if (null)if(undefined)if (0)if (NaN)if('')
cs - In order to check NaN, use (Number.isNaN(anything)
- same as Boolean()
- AND: &&
- Always need 'Comparison Operator'(비교 연산자)
- STRING METHODS = IMMUTABLE
- If you do string type + any different type, it becomes string type automatically.
12let str='Paige';console.log(str +29); // 'Paige29'cs - If you want to get length,
12let str='Paige';console.log(str.length); // 5
cs - If you want to find value,
123'Paige'.indexOf('Paige'); // 0'Paige'.indexOf('paige'); // -1'Paigee'.lastindexOf('a'); // 5
cs - if there is no value, it returns -1
- lastindexof is you find index from the back and check the order from the front.
- str.includes(searchValue) does not work at outdated browser and returns as Boolean
- If you want to seperate,
1str.split(' ')
cs - Good for CSV
- If you want to get certain values from the string,
123str = 'paige';str.substring(0, 2); // 'pa'str.slice(0, 2); // 'pa'
cs - if start value is negative, it applies as 0.
- To see difference: reference: https://stackoverflow.com/questions/2243824/what-is-the-difference-between-string-slice-and-string-substring
- If you want to Uppercase/Lowercase,
- str.toLowerCase();
- str.toUpperCase();
- Math
- ADDITIONAL
- trim() : remove space inside string
- \n : new line
- If you do string type + any different type, it becomes string type automatically.
- Need to google more about regular expressions
'TIL' 카테고리의 다른 글
TIL 2020.10.29 (0) | 2020.10.29 |
---|---|
TIL 2020.10.28 (0) | 2020.10.28 |
TIL 2020.10.26 (0) | 2020.10.26 |
TIL 2020.10.24 (0) | 2020.10.24 |
TIL 2020.10.22 (0) | 2020.10.22 |