swap function javascript
function swap(x, y) {
var t = x;
x = y;
y = t;
return [x, y];
}
console.log(swap(2, 3));let a = 1;
let b = 2;
a = a ^ b;b = a ^ b;a = a ^ b;
a; // => 2
b; // => 1let a = 1;
let b = 2;
let temp;
temp = a;a = b;b = temp;
a; // => 2
b; // => 1function swap(x, y) {
return [y, x];
}
console.log(swap(2, 3));let a = 1;
let b = 2;
a = a + b;b = a - b;a = a - b;
a; // => 2
b; // => 1let a = 1;
let b = 2;
[a, b] = [b, a];
a; // => 2
b; // => 1
Also in JavaScript:
- javascript compare maps
- react Refused to execute inline script because it violates the following Content Security Policy directive
- bootstrap 4 form validator with jquery
- angular import service
- run javascript when typing
- app.js:19465 Uncaught TypeError: Cannot call a class as a function
- Javascript check if undefined
- javascript check if string contains a text substring
- redis nodejs
- clear input jqueyr
- js running function as parameter
- inverser l'ordre des item d'un array js
- vuejs how use this.$slots.default
- A fatal JavaScript error has occurred. Should we send an error report
- using multiparty with node js express
- js standard global
- javascript pad with leading zeros
- Javascript singly linked list
- jquery disable keypress
- forin js
- java serialize object to json
- how to add make touchstart passive in jquery "3.4.0"
- not equal to sign in js
- javascript loop object