0
0
Javascriptprogramming~15 mins

Function expression in Javascript - Mini Project: Build & Apply

Choose your learning style9 modes available
Function Expression
πŸ“– Scenario: You are creating a simple calculator that can add two numbers. Instead of using a normal function declaration, you will use a function expression to keep your code neat and flexible.
🎯 Goal: Build a function expression called add that takes two numbers and returns their sum. Then use it to add two numbers and show the result.
πŸ“‹ What You'll Learn
Create a function expression named add
The function should take two parameters: a and b
The function should return the sum of a and b
Call the add function with the numbers 5 and 7
Print the result of the function call
πŸ’‘ Why This Matters
🌍 Real World
Function expressions are used in JavaScript to create flexible and reusable blocks of code, often passed as arguments or stored in variables.
πŸ’Ό Career
Understanding function expressions is essential for writing modern JavaScript code, useful in web development, backend programming, and working with frameworks.
Progress0 / 4 steps
1
Create a function expression
Create a function expression called add that takes two parameters a and b and returns their sum.
Javascript
Need a hint?

Remember, a function expression is stored in a variable. Use const add = function(a, b) { return a + b; };

2
Call the function expression
Create a variable called result and assign it the value of calling the add function with arguments 5 and 7.
Javascript
Need a hint?

Call the function like this: add(5, 7) and save it in result.

3
Print the result
Use console.log to print the value of the variable result.
Javascript
Need a hint?

Use console.log(result); to show the output in the console.

4
Run and check output
Run the program and check that the output is 12.
Javascript
Need a hint?

The output should be the sum of 5 and 7, which is 12.