표현 대 진술
식과 명령문의 기본적인 차이점은 식은 하루가 끝날 때 무언가를 반환하고 데이터를 생성하며 한 곳에 저장할 수 있다는 것입니다. 그리고 이 명령문은 데이터를 생성하지 않으며 어디에도 저장할 수 없으며 아무 것도 반환하지 않습니다. 함수 정의는 문장이고 함수 호출은 표현식입니다. 함수를 작성할 때 함수가 호출될 때까지 아무 것도 반환하지 않기 때문입니다. 화살표 함수를 쓰면 변수에 저장되기 때문에 표현식이다. 몇 가지 예를 살펴보겠습니다.
const name1 = 'Rayhan'; // Statement
const name2 = 'Alvi'; // Statement
const name3 = 'Anik'; // Statement
const name4 = 'Arjun'; // Statement
const name5 = 'Ayman'; // Statement
이것들은 모두 진술입니다. 그들은 아무것도 반환하지 않기 때문입니다.
const students = [
'Rayhan',
'Alvi',
'Anik',
'Arjun',
'Ayman',
'Ayuub',
'Bidyut',
]; // Statement
console.log(students[0]); // Expression
console.log(students[1]); // Expression
console.log(students[2]); // Expression
console.log(students[3]); // Expression
console.log(students[4]); // Expression
for (let i = 0; i < students.length; i++) {
console.log(students[i], students[i].toLowerCase()); // Expression
} // Statement
students
는 아무 것도 반환하지 않기 때문에 문입니다. console.log()
는 무언가를 반환하기 때문에 표현식입니다. for
루프는 아무 것도 반환하지 않기 때문에 문이지만 for 루프 내부의 console.log(students[i], students[i].toLowerCase())
는 표현식입니다.function nameOfFunction(name) {
if (!name) {
console.log('Please provide your name');
} else {
console.log('Hello', name);
}
} // Statement
이것을 함수문이라고 합니다. 호출될 때까지 아무 것도 반환하지 않기 때문입니다.
const nameOfFunction = function (name) {
if (!name) {
console.log('Please provide your name');
} else {
console.log('Hello', name);
}
} // Expression
이것은 변수에 저장되기 때문에 함수 표현식이라고 합니다.
nameOfFunction('Murshed'); // Expression
nameOfFunction('Fahim'); // Expression
nameOfFunction(); // Expression
모든 함수 호출은 무언가를 반환하기 때문에 표현식입니다. 반환할 항목이 없으면 최소한
undefined
를 반환합니다.function generateRandomNumber(min = 1, max) {
const randomNumber = Math.floor(Math.random() * min + (max - min)); // Statement
return randomNumber; // Expression
} // Statement
console.log(generateRandomNumber(5, 10)); // Expression
이것이 마지막 예입니다. 함수 정의
generateRandomNumber
is statement, const randomNumber = Math.floor(Math.random() * min + (max - min))
is statement, Math.floor(Math.random() * min + (max - min))
is expression, return randomNumber
is expression, console.log(generateRandomNumber(5, 10))
is expression.표현과 진술의 개념을 명확히 하기 위해 간략한 개요를 제공하려고 노력했습니다. 당신이 이해할 수 있기를 바랍니다. 😊😊
Reference
이 문제에 관하여(표현 대 진술), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/adityackr/expression-vs-statement-4gj9텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)