TIL-wecode7일차 javascript 강의
🐶위코드 7일차🐶
💯주말을 이용해 내용정리를 위해 드림코딩 엘리 강의를 듣고 정리를 하였다
//1. string concatenation
console.log('my' + 'cat');
console.log('1' + 2);
console.log(`string literals: 1+2 = ${1+2}`);
//2.Numeric operators
console.log(1+1); //add
console.log(1-1); //substract
console.log(1/1); //divide
console.log(1*1); //multiply
console.log(5%2); //remainder
console.log(2**3); //exponentiation
//3.Increment and decrement operators
let counter = 2;
const preIcrement = ++counter;
//counter = counter + 1;
//preIcrement = counter;
console.log(`preIcrement: ${preIcrement}, counter ${counter}`);
const postIncrement = counter++;
//postIncrement = counter;
//counter = counter + 1;
console.log(`postIncrement: ${postIncrement}, counter ${counter}`);
//4.assignment operators
let x = 3;
let y = 6;
x += y; //x=x+y;
x -= y;
x *= y;
x /= y;
//5.comparison operators
console.log(10<6); //less than
console.log(10<=6);//less than or equal
console.log(10>6);//greater than
console.log(10>=6);//greater than or equal
//5.Logical operators: ||(or), &&(and), !(not)
const value1 = true;
const value2 = 4<2;
//||(or), finds the first truthy value
console.log(`òr: ${value1 || value2 ||check()}`);
//&&(and), finds the first falsy value
console.log(`and: ${value1 && value2 && check()}`);
//often used to compress long if-statement
//nullbableObject && nullableObject.something
//if (nullableObject != null){
// nullableObject.something;
//}
function check(){
for(let i = 0; i<10; i++){
//wasting time
console.log('🍎')
}
return true;
}
//!(not)
console.log(!value1);
//7.Equality
const stringFive = '5';
const numberFive = 5;
//==loose equality, with type conversion
console.log(stringFive == numberFive); //true
console.log(stringFive != numberFive); //false
//===strict equality, no type conversion
console.log(stringFive === numberFive); //false
console.log(stringFive !== numberFive); //true
//object equality by reference
const ellie1 = {name: 'ellie'};
const ellie2 = {name: 'ellie'};
const ellie3 = ellie1;
console.log(ellie1 == ellie2); //false
console.log(ellie1 === ellie2); //false
console.log(ellie1 === ellie3); //true
//equality - puzzler
console.log(0 == false); //true
console.log(0 === false); //false
console.log('' == false); //true
console.log('' === false); //false
console.log(null == undefined); //true
console.log(null === undefined); //false
//8.Conditional operatorsL if
//if, else if, else
const name = 'df';
if (name === 'ellie'){
console.log('welcome, yeongjae');
} else if (name === 'coder'){
console.log('You are sexy coder');
} else{
console.log('unknown');
}
//9. Ternary operator: ?
//condition ? value1 : value2;
const nameYeongjae = 'yeongjae';
console.log(nameYeongjae === 'yeongjae' ? 'yes' : 'no');
//10. Switch statement
//use for multiple if checks
//use for enum-like value check
//use for multiple type checks in TS
const browser = 'IE';
switch (browser) {
case 'IE':
console.log('this IE');
break;
case 'Chrome':
case 'Firefox':
conseole.log('nice service');
break;
default:
console.log('same');
break;
}
//11.loops
//while loop, while the condition is truthy,
//body code is excuted.
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--){
//inline variable declaration
console.log(`'for: ${i}`);
}
//nested loops
for (let i = 0; i<10; i++){
for(let j = 0; j<10; j++){
console.log(`ì : ${i}, j : ${j}`);
}
}
//break,continue
//Question1. iterate from 0 to 10 and print only even numbers(use continue)
//question2. iterate from 0 to 10 and print numbers until reaching 8(use break)
//Question1--내풀이
for (let p = 0; p < 11; p++){
if (p%2 == 0){
console.log(`p: ${p}`);
}
continue;
}
//q1 answer
for ( let p = 0; p<11; p++){
if(p%2 !== 0){
continue;
}
console.log(`q1 : ${p}`);
}
//Question2
for(let q = 0; q <9; q++){
console.log(`q: ${q}`);
continue;
}
//q2 answer
for(let q = 0; q<11; q++){
if(q>8){
break;
}
console.log(`q2 : ${q}`);
}
Author And Source
이 문제에 관하여(TIL-wecode7일차 javascript 강의), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://velog.io/@kyj2471/TIL-wecode7일차-javascript-강의
저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
💯주말을 이용해 내용정리를 위해 드림코딩 엘리 강의를 듣고 정리를 하였다
//1. string concatenation
console.log('my' + 'cat');
console.log('1' + 2);
console.log(`string literals: 1+2 = ${1+2}`);
//2.Numeric operators
console.log(1+1); //add
console.log(1-1); //substract
console.log(1/1); //divide
console.log(1*1); //multiply
console.log(5%2); //remainder
console.log(2**3); //exponentiation
//3.Increment and decrement operators
let counter = 2;
const preIcrement = ++counter;
//counter = counter + 1;
//preIcrement = counter;
console.log(`preIcrement: ${preIcrement}, counter ${counter}`);
const postIncrement = counter++;
//postIncrement = counter;
//counter = counter + 1;
console.log(`postIncrement: ${postIncrement}, counter ${counter}`);
//4.assignment operators
let x = 3;
let y = 6;
x += y; //x=x+y;
x -= y;
x *= y;
x /= y;
//5.comparison operators
console.log(10<6); //less than
console.log(10<=6);//less than or equal
console.log(10>6);//greater than
console.log(10>=6);//greater than or equal
//5.Logical operators: ||(or), &&(and), !(not)
const value1 = true;
const value2 = 4<2;
//||(or), finds the first truthy value
console.log(`òr: ${value1 || value2 ||check()}`);
//&&(and), finds the first falsy value
console.log(`and: ${value1 && value2 && check()}`);
//often used to compress long if-statement
//nullbableObject && nullableObject.something
//if (nullableObject != null){
// nullableObject.something;
//}
function check(){
for(let i = 0; i<10; i++){
//wasting time
console.log('🍎')
}
return true;
}
//!(not)
console.log(!value1);
//7.Equality
const stringFive = '5';
const numberFive = 5;
//==loose equality, with type conversion
console.log(stringFive == numberFive); //true
console.log(stringFive != numberFive); //false
//===strict equality, no type conversion
console.log(stringFive === numberFive); //false
console.log(stringFive !== numberFive); //true
//object equality by reference
const ellie1 = {name: 'ellie'};
const ellie2 = {name: 'ellie'};
const ellie3 = ellie1;
console.log(ellie1 == ellie2); //false
console.log(ellie1 === ellie2); //false
console.log(ellie1 === ellie3); //true
//equality - puzzler
console.log(0 == false); //true
console.log(0 === false); //false
console.log('' == false); //true
console.log('' === false); //false
console.log(null == undefined); //true
console.log(null === undefined); //false
//8.Conditional operatorsL if
//if, else if, else
const name = 'df';
if (name === 'ellie'){
console.log('welcome, yeongjae');
} else if (name === 'coder'){
console.log('You are sexy coder');
} else{
console.log('unknown');
}
//9. Ternary operator: ?
//condition ? value1 : value2;
const nameYeongjae = 'yeongjae';
console.log(nameYeongjae === 'yeongjae' ? 'yes' : 'no');
//10. Switch statement
//use for multiple if checks
//use for enum-like value check
//use for multiple type checks in TS
const browser = 'IE';
switch (browser) {
case 'IE':
console.log('this IE');
break;
case 'Chrome':
case 'Firefox':
conseole.log('nice service');
break;
default:
console.log('same');
break;
}
//11.loops
//while loop, while the condition is truthy,
//body code is excuted.
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--){
//inline variable declaration
console.log(`'for: ${i}`);
}
//nested loops
for (let i = 0; i<10; i++){
for(let j = 0; j<10; j++){
console.log(`ì : ${i}, j : ${j}`);
}
}
//break,continue
//Question1. iterate from 0 to 10 and print only even numbers(use continue)
//question2. iterate from 0 to 10 and print numbers until reaching 8(use break)
//Question1--내풀이
for (let p = 0; p < 11; p++){
if (p%2 == 0){
console.log(`p: ${p}`);
}
continue;
}
//q1 answer
for ( let p = 0; p<11; p++){
if(p%2 !== 0){
continue;
}
console.log(`q1 : ${p}`);
}
//Question2
for(let q = 0; q <9; q++){
console.log(`q: ${q}`);
continue;
}
//q2 answer
for(let q = 0; q<11; q++){
if(q>8){
break;
}
console.log(`q2 : ${q}`);
}
Author And Source
이 문제에 관하여(TIL-wecode7일차 javascript 강의), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@kyj2471/TIL-wecode7일차-javascript-강의저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)