- Trending Categories
- 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
Returning the nth even number using JavaScript
Problem
We are required to write a JavaScript function that takes in a number n. And our function should simply return the nth even number in natural numbers.
Example
Following is the code −
const num = 67765; const nthEven = (num = 1) => { const next = num * 2; const res = next - 2; return res; }; console.log(nthEven(num));
Output
135528
Advertisements