본문 바로가기

JavaScript14

자바스크립트 배열 // 1. Declaration const arr1 = new Array(); //배열을 선언하는 방법2가지 const arr2 = [1 , 2]; //2. Index position const fruits = ['사과', '바나나']; console.log(fruits); console.log(fruits.length); //배열의 크기 2 console.log(fruits[0]); console.log(fruits[1]); console.log(fruits[2]); console.log(fruits[fruits.length - 1]); //배열의 마지막 데이터를 찾을때 배열의 index는 0부터 시작하므로 배열의 길이에서 -1을 해주면 배열의 가장 마지막 index안에 있는 값을찾을 수 있음 //3... 2022. 2. 18.
자바스크립트 object const obj1 ={}; //자바스크립트에서 객체만드는 방법1 'object literal' syntax const obj2 = new Object();//자바 스크립트에서 객체 만드는 방법2 'object constructor' syntax //object = {key : value}; function print(person){ console.log(person.name); console.log(person.age); } const son = {name: 'son' , age: 4}; //객체 생성 ex key: name (접근 가능한 변수) value (그 변수에 넣은 값) print(son); //출력 //2. Computed properties //자바스크립트에서 객체의 데이터에 접근하는 방법.. 2022. 2. 12.
JavaScript Class object 'use strict'; // 1. Class declarations class Person { //constructor constructor(name, age){ //parameter //fields this.name = name; this.age = age; } // methods speak(){ console.log(`${this.name}: hello`); } } const son = new Person('son', 20); //객체생성 console.log(son.name); console.log(son.age); son.speak(); //2.Getter and setters class User{ constructor(firstName, lastName, age){ this.firstName .. 2022. 2. 3.
자바스크립트 5. Arrow Function function changeName(obj){ obj.name ='coder'; } const son = {name : 'son'}; changeName(son); console.log(son); // 3.Default parameters (added in ES6) function showMessage(message, from) { console.log(`${message} by ${from}`); } showMessage('Hi!'); // 4.Rest parameters (added in ES6) function printAll(...args){ //args 3개의 값을 담고 있는 배열 for(let i =0;i console.log('simplePrint'); const add = (a,b) => .. 2022. 1. 29.