- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Product of two number using HOC - JavaScript
HOC
HOC or Higher Order Functions in JavaScript are a special type of functions that receives another function as argument or have a function set as their return value or do both. HOC along with closures is a very powerful tool in JavaScript.
We are required to write a JavaScript Higher Order Function that can be used to obtain the product of two numbers.
Example
Following is the code −
const num1 = 24; const num2 = 5; const productHOC = num1 => { return product = num2 => { return num1 * num2; }; }; console.log(productHOC(num1)(num2));
Output
Following is the output in the console −
120
Advertisements