JavaScript Math SQRT1_2
Syntax & Examples


Math.SQRT1_2 static-property

The Math.SQRT1_2 property represents the square root of ½, which is approximately equal to 0.707.


Syntax of Math.SQRT1_2

The syntax of Math.SQRT1_2 static-property is:

Math.SQRT1_2

This SQRT1_2 static-property of Math square root of ½; approximately 0.707.



✐ Examples

1 Using Math.SQRT1_2 to calculate a scaled value

In JavaScript, we can use the Math.SQRT1_2 property to scale down a value by the square root of ½.

For example,

  1. We create a variable value and set it to 10.
  2. We calculate the scaled value using value * Math.SQRT1_2.
  3. The result is stored in the variable scaledValue.
  4. We log scaledValue to the console using the console.log() method.

JavaScript Program

const value = 10;
const scaledValue = value * Math.SQRT1_2;
console.log(scaledValue);

Output

7.0710678118654755

2 Using Math.SQRT1_2 in a geometric transformation

In JavaScript, we can use the Math.SQRT1_2 property in geometric transformations, such as scaling coordinates.

For example,

  1. We create variables x and y representing coordinates.
  2. We calculate the scaled coordinates using x * Math.SQRT1_2 and y * Math.SQRT1_2.
  3. The results are stored in variables scaledX and scaledY.
  4. We log scaledX and scaledY to the console using the console.log() method.

JavaScript Program

const x = 8;
const y = 6;
const scaledX = x * Math.SQRT1_2;
const scaledY = y * Math.SQRT1_2;
console.log(scaledX, scaledY);

Output

5.656854249492381 4.242640687119285

3 Using Math.SQRT1_2 in a trigonometric function

In JavaScript, we can use the Math.SQRT1_2 property in trigonometric functions to simplify calculations.

For example,

  1. We create a variable angle and set it to 45 degrees, converted to radians.
  2. We calculate the sine of the angle using Math.sin(angle).
  3. We use Math.SQRT1_2 to verify the result, as the sine of 45 degrees is equal to the square root of ½.
  4. We log the calculated sine and the value of Math.SQRT1_2 to the console using the console.log() method.

JavaScript Program

const angle = 45 * (Math.PI / 180);
const sineValue = Math.sin(angle);
console.log(sineValue, Math.SQRT1_2);

Output

0.7071067811865475 0.7071067811865476

Summary

In this JavaScript tutorial, we learned about SQRT1_2 static-property of Math: the syntax and few working examples with output and detailed explanation for each example.