log는 console이라는 object(객체) 안의 function(함수)
*function에 외부의 값을 입력하는 방법
1) 함수function 외부에서 변수variable에 값argument을 부여
2) 함수function를 통해 값을 반환return
3) console.log에서 이 이름을 사용하여 값을 console한다
예) 객체와 함수
const calculator = { plus: function(a, b){ return a + b; } } const plus = calculator.plus(5, 5); console.log(plus); /* returned value = 5 + 5 = 10; object : calculator; variable : plus; argument : 5, 5; */
예) 각각의 변수를 선언하고 값을 부여하는 경우
const name = "SEOHA"; const age = 28; const gender = "Female"; console.log(name, age, gender); ***console 결과 : SEOHA 28 Female
예) Array를 사용하는 경우
const arrayInfo = ["SEOHA", 28, "Female"]; console.log(arrayInfo); ***console 결과 : [ 'SEOHA', 28, 'Female' ]
예) Object를 사용하는 경우
const objectInfo = {name:"SEOHA", age:28, gender:"Female"} console.lof(objectInfo); ***console 결과 : { name: 'SEOHA', age: 28, gender: 'Female' }
Array는 단순한 list로 나열밖에 할 수 없지만
Object는 실제 객체를 만드는 것 = 저장하고 싶은 data에 label을 주는 것
Array는 []
Object는 {}
사용
gender의 info만 필요할 때
**Array** console.log(arrayInfo[2]); -> Array의 순서를 기억해야 함 console.log(objectInfo.gender); -> data의 이름만 사용하여 표시 가능
Object 안에 Array 중첩 사용 가능
const seohaInfo = { name: "seoha", age: 28, gender: "Female", favFoods: ["Icecream", "Melon"], mySiblings: [ { name:"Bogyung", gender:"Female" }, { name:"Duhyung", gender:"Male" } ] } console.log(seohaInfo);
-> console 결과 : name: 'seoha', age: 28, gender: 'Female', favFoods: [ 'Icecream', 'Melon' ], mySiblings: [ { name: 'Bogyung', gender: 'Female' }, { name: 'Duhyung', gender: 'Male' }