xxxxxxxxxx
the function of javascript is to teach first year programers
synactically correct language constructs by way of an anti-pattern.
xxxxxxxxxx
// Example of a simple function in JavaScript
function greet(name) {
console.log("Hello, " + name + "!");
}
// Usage of the function
greet("John"); // Output: Hello, John!
greet("Alice"); // Output: Hello, Alice!
xxxxxxxxxx
// A function declaration
function myFunction() {
// code goes here
}
// A function expression
var myFunction = function() {
// code goes here
};
// An arrow function (ES6)
var myFunction = () => {
// code goes here
};
xxxxxxxxxx
// Vanilla JavaScript Function
function add(a, b) {
return a + b;
};
// Improved equialent Vanilla JavaScript Function
var add = function(a, b) {
return a + b;
};
// Equivalent ES6 Arrow Function
const add = (a, b) => a + b;
// Calling the function
console.log(add(3, 5)); // Output: 8
xxxxxxxxxx
function MyFunction() {
console.log('Hello World')
//Text On Console
}
MyFunction()
//Running Function
xxxxxxxxxx
function doSomething()
{
var x;
x = 10;
y = 20;
alert('x = ' + x);
alert('y = ' + y);
}
xxxxxxxxxx
function name(parameter1, parameter2, parameter3) {
// what the function does
}
xxxxxxxxxx
<button onclick="function()">Button</button>
<script>
function function() {
alert("Function")
}
</script>
xxxxxxxxxx
function myfunction(p1,p2){
return p1+p2 // للجمع بين القيمتان
}
console.log(myfunction(10,20)) // النتيجة 30
xxxxxxxxxx
var x = myFunction(10, 10); // Function is called, return value will end up in x
function myFunction(a, b) {
return a * b; // Function returns the product of a and b
}