본문 바로가기

javascript

javascript ES6란?

자바스크립트 ES6 문법이란?

//11 숫자인지 판단하기
console.log("=11========================================================")
const isNaN123 = isNaN(123);
const isNaNMinus123 = isNaN(-123);
const isNaN234 = isNaN("234");
const isNaNHello = isNaN("Hello");
console.log("isNaN123 : ", isNaN123);
console.log("isNaNMinus123 : ", isNaNMinus123);
console.log("isNaN234 : ", isNaN234);
console.log("isNaNHello : ", isNaNHello);

//10 문자와 숫자
console.log("=10========================================================")
const string10 = "10";
const string20 = "20";
const number10 = 10;
const number20 = 20;
console.log("string:%s", string10 + string20);
console.log("number:%d", number10 + number20);
console.log("string + number:%s", string10 + number20);

//09 let 변수와 const 상수
console.log("=09========================================================")
let fruit1 = "apple";
fruit1 = "banana";
const pi = 3.14;
console.log("fruit1 : ", fruit1);
console.log("pi : ", pi);

//08 let 변수
console.log("=08========================================================")
let fruit = "apple";
console.log("fruit : ", fruit);
fruit = "grape";
console.log("fruit : ", fruit);

//07 주석
console.log("=07========================================================")
console.log("Hello, kangAgee");
// console.log("Hello, KangAgee"); 한줄주석
/*여러줄 주석
console.log("Hello, KangAgee");
console.log("Hello, Goyangi");
*/

//06 백틱
console.log("=06========================================================")
const greeting1 = "hello";
const greeting2 = "bye";
const name1 = "KangAgee";
const name2 = "Goyangi";

const statement = `${greeting1}! My name is ${name2}`;
const statement2 = `${greeting2}! My name is ${name2}`;

console.log(`${greeting1}! My name is ${name1}`);
console.log(`${greeting2}! My name is ${name1}`);
console.log("statement : ", statement);
console.log("statement2 : ", statement2);

//05 Formatting
console.log("=05========================================================")
console.log("name:%s", "KangAgee");
console.log("age:%d", 31);
console.log("pi:%d", 3.14);
console.log("math:%d science:%d", 92,84);
console.log("name:%s age:%d", "KangAgee",31);
console.log("name:%s math:%d science:%d", "KangAgee", 92, 84);
console.log("name:%s math:%s science:%s", "KangAgee", 92, 84);

//04 Hello World
console.log("=04========================================================")
console.log("Hello", "World");
console.log(`I love coding, This line ${'can make error'}`);

ES6는 ECMA라는 국제 기구에서 만든 ECMAScript 표준 문서의 6번째 개정판 문서에 있는 표준 스펙입니다. ES2015라고도 쓰는데, 6번째 버전이 2015년도에 나왔기 때문입니다. ECMAScript의 7번째 버전은 ECMAScript7 또는 ES7라고 쓰고 2016년에 나왔기 때문에 ES2016이라고 부릅니다.

//18 배열(array) 출력
console.log("=18========================================================");
const arCoffee = [];
arCoffee.push("Cappuccino");
arCoffee.push("Caffe Latte");
arCoffee.push("Caffe Mocha");
arCoffee.push("Americano","Espresso","Caramel macchiato");
console.log("arCoffee : ", arCoffee);
console.log("arCoffee length : ", arCoffee.length);
console.log("arCoffee[6] : ", arCoffee[6]);
console.log("arCoffee[0] : ", arCoffee[0]);

//17 배열(array) 선언
console.log("=17========================================================");
const arNumbers = [];
arNumbers.push(1);
arNumbers.push(2);
arNumbers.push(3);
const arTexts = [];
arTexts.push('hello', 'welcome', 'bye');
console.log(arNumbers);
console.log(arTexts);

//16 배열(array) 선언
console.log("=16========================================================");
const numbers_ = [1, 2, 3];
const strings = ['hello', 'bye', 'welcome'];
// new Array()를 이용하는 방법은 []를 이용하는 방법과 동일. []를 이용하는게 좋음.
const numbers_2 = new Array(1,2,3);
const strings2 = new Array('hello', 'bye', 'welcome');
console.log('numbers_ : ', numbers_);
console.log('numbers_2 : ', numbers_2);
console.log('strings : ', strings);
console.log('strings2 : ', strings2);

//15 문자열 찾기 indexOf()
console.log("=15========================================================");
const string_1 = 'hello';
const string_2 = 'helelelelelello';
const string_3 = 'The method then selects elements from the start argument.';
console.log('hel : ', string_1.indexOf('hel'));
console.log('el : ', string_1.indexOf('el'));
console.log('elelelel : ', string_2.indexOf('elelelel'));
console.log('method : ', string_3.indexOf('method'));
console.log('bye : ',string_3.indexOf('bye'));

//14 문자열 개수 세기 .length
console.log("=14========================================================");
const string = 'hello';
const string2 = 'The method then selects elements from the start argument, and up to (but not including) the end argument.';
console.log('string:', string.length);
console.log('string2:', string2.length);
console.log('string[0]:', string[0]);
console.log('string2[104]:', string[104]);

//13 나머지 구하기 - 홀수, 짝수 판단
console.log("=13========================================================");
console.log('5 % 2 :', 5%2);
const numbers = [5,6,7,8];
console.log(numbers[0], 'is even number:', numbers[0] % 2 === 0);
console.log(numbers[1], 'is even number:', numbers[1] % 2 === 0);
console.log(numbers[2], 'is even number:', numbers[2] % 2 === 0);
console.log(numbers[3], 'is even number:', numbers[3] % 2 === 0);

//12 더하기, 빼기, 곱하기, 나누기
console.log("=12========================================================");
const number10 = 10;
const number20 = 20;
const plusResult = number10 + number20;
const minusResult = number10 - number20;
const multipleresult = number10 * number20;
const divideResult = number10 / number20;
console.log('10 + 20 = ', plusResult);
console.log('10 - 20 = ', minusResult);
console.log('10 * 20 = ', multipleresult);
console.log('10 / 20 = ', divideResult);

 

 

728x90
300x250