728x90
반응형
- String conatenation
- console.log('my' + 'cat'); //my cat console.log('1' + '2'); //12 console.log(`string literals: 1 + 2 = ${1 + 2}`); //string literals: 1 + 2 = 3
- Numeric operators
- console.log(1 + 1); console.log(1 - 1); console.log(1 * 1); console.log(1 / 1); console.log(5 % 2); //remainder 나머지 값 1 console.log(2 ** 3); //제곱 8
- Increment 증가 연산자 /감소도 같은 방식
let counter = 2; const preIncrement = ++counter; //counter = counter + 1; //preIncrement = counter; console.log(preIncrement:${preIncrement}, counter:${counter}) //preIncrement:3, counter:3 const postIncrement = counter++; //preIncrement = counter; //counter = counter + 1; console.log(postIncrement:${postIncrement}, counter:${counter}) //postIncrement:3, counter:4 i++(후위연산자) // i = i + 1 ++i(전위연산자) // i = i + 1 i += 1 // i = i + 1 i += 5 // i = i + 5 var i=0 console.log(i++) // 0 console.log(i++) // 1 console.log(i++) // 2 var i=0 console.log(++i) // 1 console.log(++i) // 2 console.log(++i) // 3 */
- i++ 후위증가연산자 : 변수를 먼저 할당하고 값을 변경. ++i 전위증가연산자 : 변수의 값을 변경 시키고 할당.
- Assign operatorsx -= y; // x = x - yx /= y;
- x *= y;
- x += y; // x = x + y ;
- Comparison operator 비교 연산자 <≤ ≥
- Logical operator 논리 연산자 || (or)
- 가장 처음의 true에서 멈추기 때문에 코드를 짤 때는 최대한 가벼운 것이 앞에 오게 짠다.(false가 오더라도 초반의 연산이 빨리 끝나게끔)
- &&도 무거운 연산을 뒤에 짠다 ** null 체크할 때도 많이 쓰임
- ! (not)
- && (and)
- 1️⃣ value 중 하나라도 true면 true
- Equality operator 관계 연산자 = == 동등 연산자(추상적)//type이 다르더라도 === 일치 연산자(엄격)//type까지 완벽하게 똑같을 때
if 반복문
if (condition) {
function
}
else if (condition){
function
}
else{
function
}
- Ternaty operator 삼항 연산자
//condition ? value1 : value2
console.log(name === 'sulki' ? 'Y':'N')
9.Switch operator 반복되는 검사
const browser = 'chorme',
switch(browser) {
case 'chrome':
console.log('good');
break;
case 'IE';
console.log('bye');
break;
}
while 반복문 loop
let i = 3;
while (i > 0) {
console.log(`while: ${i}`);
i--;
//i가 1까지 반복해서 출력된다 3-2-1
do while
for loop
for(begin; condition; step)
for(i = 0; i<=10; i++){
function
}
728x90
반응형
'JavaScript' 카테고리의 다른 글
JavaScript 출력 (0) | 2023.06.14 |
---|---|
Javascript 규칙 (0) | 2023.06.14 |
Data Type (0) | 2023.04.24 |
Return (0) | 2023.04.24 |
CSS in JS (0) | 2023.04.24 |
댓글