JavaScript program to swap two variables Using Arithmetic Operators

Pubblicato il: 03 novembre 2022
sul canale di: Tech Tips
136
2

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


In questa pagina del sito puoi guardare il video online JavaScript program to swap two variables Using Arithmetic Operators della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Tech Tips 03 novembre 2022, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 136 volte e gli è piaciuto 2 spettatori. Buona visione!