HTML
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<link name="favicon" type="image/x-icon" href="https://skillzam.com/uploads/system/e353194f3b7cd1b75d69c3ab88041985.png" rel="shortcut icon" />
<title>Function Expression</title>
</head>
<body>
<!--
Function expression is another syntax for creating a function in JavaScript.
Function expression can be stored in a variable. They are always invoked (called) using variable name.
Function name can be omitted in function expressions to create "anonymous" functions.
Function expressions are NOT hoisted in JavaScript, unlike function declarations. It will throw an "ERROR" TypeError: notHoisted is not a function.
-->
<h1>Demo: Function Expression</h1>
<p id="para"></p>
<!-- JavaScript code Starts here -->
<script>
/************************************************/
// Function Expressions
// Example : Find the area of the rectangle
//
let area;
const rectangleArea = function (length, breadth) {
return length * breadth;
}
area = rectangleArea(6, 4);
document.getElementById('para').innerHTML =
`The area of a rectangle is = ${area} sq units.`;
</script>
<!-- JavaScript code Ends here -->
</body>
</html>