Dans cet exemple, on apprend à écrire un programme pour échanger deux variables en JavaScript:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Permutation</title>
</head>
<body>
<script language="javascript" src="lib.js">
</script>
</body>
</html>
Le code javascript (lib.js) :
a=Number(prompt("a=",""));
b=Number(prompt("b=",""));
a=a+b;
b=a-b;
a=a-b;
alert("après la permutation a="+a);
alert("après la permutation b="+b);