Program to Swap Two Numbers With or Without Third Variable
javascript tutorial to swap two values using third variable
How to Swap Two Variables Without Using Third Variable in Javascript
Swapping numbers using an ES6 Concept (without third variable)
Swap two numbers without using third (temporary) variable
How to Swap Two Numbers Without Temp or Third Variable in Javascript
Swap two numbers without using third (temporary) variable
How to swap two numbers without using temporary variable
With mathematical operations
a = a + b
b = a - b
a = a - b
XOR
For instance, you can use the bitwise XOR operator:
a = a ^ b
b = a ^ b
a = a ^ b
Single line swapping with addition
a = b + (b=a, 0)
1. (b=a, 0) sets b to the old value of a and yields 0
2. a = b + 0 sets a to the old value of b
Since ES6, you can also swap variables more elegantly.
You can use destructuring assignment array matching:
[a, b] = [b, a]
a=(a*b)/(b=a);
Look into other coding challenges:
sum(2)(3) and sum(2, 3) Amazon UI/Frontend Javascript Interview Question
Link: • sum(2)(3) and sum(2, 3) Amazon UI/Fr...
Reverse a String using JavaScript ES6 (Coding Challenge)
Link: • Reverse a String using JavaScript ES6...
Longest word in a String Using JavaScript ES6 (Coding Challenge)
Link: • Longest word in a String Using JavaSc...
=== vs == in javascript
Link: • === vs == in javascript
Factorial Of a Number Using Javascript ES6 (Coding Challenge)
Link: • Factorial Of a Number Using Javascrip...
For Loop Using JavaScript
Link: • For Loop Using JavaScript
JavaScript ES6 : Difference between var, let and const
Link: • JavaScript ES6:Difference between var...
Swap Two Numbers without using Third Variable Using JavaScript ES6 (Coding Challenge)
Link: • Swap Two Numbers without using Third ...
FizzBuzz problem using JavaScript ES6 (Coding Challenge)
Link : • FizzBuzz problem JavaScript ES6 (Cod...
Capitalize the First Letter of a String Using JavaScript (Coding challenge)
Link: • Capitalize the First Letter of a Stri...
Star(Pattern) Logical Program Using JavaScript (Coding challenges)
Link: • Star(Pattern) Logical Program Using ...
Star(Pattern) Logical Program Using JavaScript (Coding challenges)
Link: • Star(Pattern) Logical Program Using ...
For Any Queries/coding solutions/Technical Support:
Drop us mail : [email protected]
Disclaimer:
(Note: UPSKILL DURING COVID19 PANDEMIC
Free Tutorials
Let us help in using this time to upskill yourself by remote
learning programs
All videos are for knowledge sharing purpose.
Any video may have a slight mistake, please take decisions based on your research.
This video is not forcing anything on you.)