Basic Javascript Examples — Part 1
How to swap two variables in JavaScript?
Before starting to swap 2 variable examples, there are a few basic examples of Javascript in Postman.
The best way to learn JavaScript is by practicing examples. The page contains some basic examples written in JavaScript in Postman.
Here, we are clearing the console in the first step (we are doing this in the pre-request part) Then we are writing some tests in the Test part.
On the right side, you can see the test result and below you can take a look at the console. As you can see, the request is sent after running the pre-request. Plus, tests are run after the request is sent.
Below, we have some variables such as firstName, fullName, age and info.. you can see what the “info” is by looking at the console.
How to swap two variables in JavaScript?
The first way to do that is by using arrays.
The 2nd way to do that is by using a temporary variable.
Here, temp is the new 3rd variable that we are using to swap the value of variables a and b.
The 3rd way to do that is by using a destructing-assignment
Thanks and have a nice testing day! Stay tuned :)