함수 바깥으로 결과 가져오기.
console.log는 단순 출력(print)만 하기 때문에 return 이라는 키워드를 사용해 출력 결과를 가져올 수 있어야한다.
함수 안에 console.log만 있다면 그 함수는 결과값이 없는 함수가 된다.
const checkThatTwoPlusTwoEqualsFourAMillionTimes = () => {
for(let i = 1; i <= 1000000; i++) {
if ( (2 + 2) != 4) {
console.log('Something has gone very wrong :( '); // Q1. so this console.log is not the same as return keyword? NO
}
}
};
const is2p2 = checkThatTwoPlusTwoEqualsFourAMillionTimes;
is2p2(); // Q2. this invokes the function, but doesn't give the return value? BECAUSE the function checkThatTwoPlusTwoEqualsFourAMillionTimes doens't have any "return" values.
console.log(is2p2.name); // Q3. How does this print the original function name? CONSOLE.LOG simply "prints" anything in it. Because of the name property, ".name" returns the name of a function
'JavaScriptVeryBeiginning' 카테고리의 다른 글
DOM(doc obj model) (0) | 2020.07.09 |
---|---|
HTML opening default (0) | 2020.07.01 |
Using let keyword in relation to reassignment and scope pollution (0) | 2020.06.20 |
var과 let의 차이? (0) | 2020.06.18 |
function(name) name must be input as a string (0) | 2020.06.17 |