[javascript] 망설이지 마!첫 번째 반환값(return)[삽화 해설]
3300 단어 JavaScriptconsolereturn반환값tech
나는 취임 전 자습 시대에도 리턴의 필요성을 몰랐다.
학교와 직장 선배들이 알기 쉬운 설명을 해주셔서 삽화로 정리해봤어요.
다음 코드는 대입된 숫자를 두 배로 console입니다.로그로 표시된 간단한 함수.
function double(value){
const hang = value * 2;
return hang;
}
const result = double(10);
console.log(result);

결말이 없으면 어떻게 되는 거야!?
function double(value){
const hang = value * 2;
// return data;
}
const result = double(10);
console.log(result);

왜 이렇게 됐지?
리턴이 존재하지 않으면, 이번 코드에서 더블 함수를 계산했지만, 결과는 대입되지 않았습니다.
나는 답장을 받을 때의 절차를 삽화로 만들어 보았다.
세 번째 줄에서return을 사용하여result 변수를 대입하는 값을 되돌려줍니다.이것은 속칭 반환값이다.

리턴 출력 (삭제) 시 그림 여기 ↓

Reference
이 문제에 관하여([javascript] 망설이지 마!첫 번째 반환값(return)[삽화 해설]), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://zenn.dev/miumi/articles/49f7dccf4b6406dea287텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)