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
// 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
// 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
/*A function statement starts with the function keyword.
It can return a primitive type value, object, or another function.
For example, a function statement can return an object as shown in the following code example:*/
function getProduct(){
let product = {
Id:1,
Title:'Book',
Price: 30
};
return product;
}
let p1 = getProduct();
console.log(p1); // prints product object
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>