Example 3: Using Arithmetic Operators
//JavaScript program to swap two variables
//take input from the users
let a = parseInt(prompt('Enter the first variable: '));
let b = parseInt(prompt('Enter the second variable: '));
// addition and subtraction operator
a = a + b;
b = a - b;
a = a - b;
console.log(`The value of a after swapping: ${a}`);
console.log(`The value of b after swapping: ${b}`);
Run Code
Output
Enter the first variable: 4
Enter the second variable: 2
The value of a after swapping: 2
The value of b after swapping: 4
Sur cette page du site, vous pouvez voir la vidéo en ligne JavaScript program to swap two variables Using Arithmetic Operators durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur Tech Tips 03 novembre 2022, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 136 fois et il a aimé 2 téléspectateurs. Bon visionnage!