
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Subtracting two numbers without using the (-) sign JavaScript
We are required to write a JavaScript function that takes in two numbers and returns their difference but without using the (-) sign
Example
Following is the code −
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
Following is the output in the console −
22
- Related Questions & Answers
- Program for subtracting two matrices.
- Checking an array for palindromes - JavaScript
- Find the Sum of two Binary Numbers without using a method in C#?
- Addition of two numbers without propagating Carry?
- How to get the product of two integers without using * JavaScript
- Finding the sum of two numbers without using '+', '-', '/', '*' in JavaScript
- The globals(), locals() and reload() Functions in Python
- The time Module in Python
- The calendar Module in Python
- The Anonymous Functions in Python
- The return Statement in Python
- The import Statements in Python
- The Threading Module in Python
- The match Function in Python
- The search Function in Python
Advertisements