- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- 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

# Performing the subtraction operation without the subtraction operator in JavaScript

We are required to write a JavaScript function that takes in two numbers and returns their difference but without using the (-) sign.

Therefore, let’s write the code for this function −

## Example

The code for this will be −

const num1 = 56; const num = 78; const subtractWithoutMinus = (num1, num2) => { if(num2 === 0){ return num1; }; return subtractWithoutMinus(num1 ^ num2, (~num1 & num2) << 1); }; console.log(subtractWithoutMinus(num, num1));

## Output

The output in the console will be −

22

- Related Articles
- What is Subtraction Operator (-) in JavaScript?
- Non-negative set subtraction in JavaScript
- JavaScript subtraction of two float values?
- What are the properties of subtraction?
- What is the subtraction of binary numbers?
- Complete the addition-subtraction box.(a)(b)"
- Performing an operation, such as addition, subtraction, multiplication or division, on any two integers and the result will always be an integer. This property of integers is known as
- Construct Turing machine for subtraction
- Explain the addition and subtraction of integers with examples.
- Swift Program to Find the Subtraction of Two Sets
- Instructions to perform subtraction in 8085 Microprocessor
- What is BCD Subtraction in Computer Architecture?
- Calculate Subtraction of diagonals-summations in a two-dimensional matrix using JavaScript
- How will addition, subtraction, multiplication and division operator work with date values stored in MySQL table?
- C Program for subtraction of matrices

Advertisements