Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
Tags
- supabase 페이지네이션
- generic
- 안드로이드빌드에러
- async
- materialicons
- mainapplication.kt
- extends
- 리액트네이티브아이콘
- Next.js
- react
- interface
- 슬라이딩윈도우
- 글또10기
- 배열중복요소제거
- reactnative
- 이진탐색
- Spring
- Filter
- TS
- javascript
- 페이지네이션
- 타입스크립트
- app:compiledebugkotlin
- set
- map
- 상속
- app.post
- 스크롤이벤트
- array
- meatadata
Archives
- Today
- Total
rhanziy
javascript. 연산자, 반복문 본문
// string concatenation
console.log('my' + 'cat');
console.log('1'+2);
console.log(`string literals: 1+2 = ${1+2}`);
console.log (`rhanyi's \n\tbook`); // \n 줄바꿈 \t 탭
// numeric operators
console.log(1+1); //add
console.log(1-1); // subtract
console.log(1/1); // divide
console.log(1*1); // multiply
console.log(5%2); // remainder
console.log(2**3); //exponentiation
// Increment and decrement operators
let counter = 2;
const preIncrement = ++counter;
// 1. counter = counter + 1 ; 선행
// 2. preIncrement = counter;
console.log(`preIncrement: ${preIncrement}, counter: ${counter}`);
const postIncrement = counter ++;
// 1. postIncrement = counter;
// 2. counter = counter+1; 후행
console.log(`preIncrement: ${preIncrement}, counter: ${counter}`);
// Assignment oprators
let x = 3;
let y = 6;
x += y; // x = x+y; 누적
//x -= y; x*=y; x/=y;
// Comparison operators
console.log(10<6); // less than
console.log(1<=1); // less than or equal
console.log(1>1); // greater than
console.log(1>=1); // greater than or equal
// Logical operators : || (or), &&(and), !(not)
const value1 = false;
const value2 = 4 < 2;
console.log(`or: ${ value1 || value2 || check() }`); // value1이 true면 끝.
console.log(`and: ${ value1 && value2 && check() }`); // value1이 false면 끝.
function check() {
for (let i = 0; i <10; i++){
console.log('ㅇ_ㅇ');
}
return true;
}
console.log(!value1); // true
// Equality
const stringFive = '5';
const numberFive = '5';
// == loose equality, with type conversion
console.log( stringFive == numberFive );
console.log( stringFive != numberFive );
// === strict equality, no type conversion
console.log( stringFive === numberFive ); // 자료형까지 비교
console.log( stringFive !== numberFive );
// object equality by reference
const rhanyi1 = { name:'rhanyi' };
const rhanyi2 = { name:'rhanyi' };
const rhanyi3 = rhanyi1;
console.log( rhanyi1 == rhanyi2 ); // false
console.log( rhanyi1 === rhanyi2 ); // false
console.log( rhanyi1 == rhanyi3 ); // true
// equality - puzzler
console.log( 0 == false ); // true
console.log ( 0 === false ); // boolean타입 x -> false
console.log( '' == false); // true
console.log( '' === false ); // boolean타입 x -> false
console.log( null == undefined ); // true
console.log( null === undefined ); // false
// Ternary operator
console.log( name === 'rhanyi' ? 'yes' : 'no');
// Switch statement
const browser = 'Safari';
switch (browser) {
case 'IE':
console.log('go away!');
break;
case 'Chrome':
case 'Firefox':
console.log('hi there~');
break;
default:
console.log('same all!');
break;
}
// Loops
let i = 3;
while( i > 0 ) {
console.log(`while: ${i}`);
i--;
}
// do while loop, body code is executed first, then check the condition
do {
console.log(`do while : ${i}`);
i--;
} while ( i > 0 );
// for loop, for(begin; condition; step)
for ( i = 3; i > 0; i -- ){
console.log(`for: ${i}`);
}
for ( let i = 3; i > 0; i = i - 2 ){
console.log(`iline variable for: ${i}`);
}
// nested loops
for ( let i = 0; i < 10; i ++ ){
for( let j = 0; j < 10; j++ ){
console.log(`i: ${i}, j: ${j}`);
}
}
// test continue, break
for ( i = 0; i < 11; i++ ) {
if( i % 2 === 0 ) {
continue; // skip개념
}
console.log(i);
}
for ( i=0; i < 11; i++ ){
if( i > 8 ) {
break;
}
console.log(i);
}
'Html_css_js' 카테고리의 다른 글
javascript. 함수 function (0) | 2022.01.18 |
---|---|
js. 스크롤 한 높이값 만큼 컨텐츠 position 이동하기 (0) | 2022.01.17 |
javascript. script태그 async 와 defer의 차이점 (0) | 2022.01.16 |
css.반응형 폰트사이즈 관련 팁 (0) | 2021.12.30 |
css.background, drop-shadow (0) | 2021.12.20 |
Comments