
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
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 Articles
- Program for subtracting two matrices.
- Java Program to Add two Numbers without using Arithmetic Operator
- Finding the sum of two numbers without using '+', '-', '/', '*' in JavaScript
- Reverse numbers in function without using reverse() method in JavaScript
- How to get the product of two integers without using * JavaScript
- Find the Sum of two Binary Numbers without using a method in C#?
- How to swap two numbers without using the third or a temporary variable using C Programming?
- How to swap two numbers without using a temp variable in C#
- C Program to find sum of two numbers without using any operator
- Largest of two distinct numbers without using any conditional statements or operators
- Addition of two numbers without propagating Carry?
- Find HCF of two numbers without using recursion or Euclidean algorithm in C++
- Write a Golang program to swap two numbers without using a third variable
- Finding LCM of more than two (or array) numbers without using GCD in C++
- Change the case without using String.prototype.toUpperCase() in JavaScript

Advertisements