Use with statement with Math object in JavaScript

Description

The following code shows how to use with statement with Math object.

Example


<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">
var myNum = 25;<!--from ww w.  ja  v a2s  .  c  o m-->

var myE, mySin, mySqrt;

with (Math) {
myE = E;
mySqrt = sqrt(myNum)
document.writeln(mySqrt+"<br/>");
mySin = sin(PI/myNum);
document.write(mySin);
}
</script>
</body>
</html>

Click to view the demo

The code above generates the following result.

Use with statement with Math object in JavaScript
Home »
  Javascript Tutorial »
    Statement »
      While
Javascript Tutorial While
Check the loop counter for while loop in Ja...
Use Do while loop to reverse a string in Ja...
Use do...while loop and int number to contr...
Use integer variable to control the while l...
Use number to control do...while loop in Ja...
Use while loop to pop all elements in an ar...
Use while loop with an integer to control t...
Use with statement with Math object in Java...