Function:
It is set of instruction to perform the task
function can be declared under the { }
Function Define in Java script:
function function name () {
}
() - this brackets are used to get the parameters from the user
Once we define the function we call at many time we want in the program running
Function calling in java script:
Function name ()
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Basic Arithmetic in JS</title>
<script>
function add(num1, num2) {
console.log("Addition of numbers:", num1 + num2);
}
function sub(num1, num2) {
console.log("Subtraction of numbers:", num1 - num2);
}
function multi(num1, num2) {
console.log("Multiplication of numbers:", num1 * num2);
}
function division(num1, num2) {
console.log("Division of numbers:", num1 / num2);
}
function mod(num1, num2) {
console.log("Modulus of numbers:", num1 % num2);
}
// Call the functions after defining them
add(5, 10);
sub(10, 5);
multi(5, 2);
division(10, 5);
mod(10, 5);
</script>
</head>
<body>
</body>
</html>
Top comments (0)