📚 › JavaScript: make pages do things
7. Functions
ستتم ترجمة هذا المقال تلقائيًا. يُعرض بالإنجليزية حاليًا.
A function is a named block of code you can run many times. Write it with the word function, a name, parameters in brackets and the code in braces. return sends a value back.
Functions let you write logic once and reuse it everywhere.
عرض المثال
function greet(name) {
return "Hello, " + name;
}
console.log(greet("Ayesha"));
✍️ دورك الآن
Write double(x) that returns x times 2, then print double(21).