xxxxxxxxxx
function myFunction() {
// function body
// add your logic here
}
// Example usage:
myFunction(); // Calling the function
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
function world(params){
//Code to be executed when the function is called.
}
world()
//Explaination
//'world' in the function is the name of the function.
//There are brackets after function name. Those are use to push parameters
//The forth line Calls the function named 'world'
xxxxxxxxxx
// Code by DiamondGolurk
// Defining the function
function test(arg1,arg2,arg3) {
// Insert code here.
// Example code.
console.log(arg1 + ', ' + arg2 + ', ' + arg3)
}
// Running the function
test('abc','123','xyz');
// Output
// abc, 123, xyz
xxxxxxxxxx
// Function declaration
function myFunction() {
// Function body
// Code to be executed
}
// Example function declaration
function greet() {
console.log("Hello, world!");
}
// Function invocation
greet(); // Output: Hello, world!
xxxxxxxxxx
// Creating a function in JavaScript
function myFunction() {
// function logic goes here
}
// An example usage of the function
myFunction();
xxxxxxxxxx
function myFunction(p1, p2) {
return p1 * p2;
// The function returns the product of p1 and p2
}
xxxxxxxxxx
<select class="form-select form-select-lg mb-3" aria-label="Large select example">
<option selected>Open this select menu</option>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>
<select class="form-select form-select-sm" aria-label="Small select example">
<option selected>Open this select menu</option>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>
xxxxxxxxxx
function myFunc(theObject) {
theObject.make = "Toyota";
}
const mycar = {
make: "Honda",
model: "Accord",
year: 1998,
};
console.log(mycar.make); // "Honda"
myFunc(mycar);
console.log(mycar.make); // "Toyota"