NSB Cosmic Center Image

N.S.B. Cosmic Center

NSB Cosmic Center Image

JavaScript & MathScript Interactive Document Generator-Demo-02

This document is generated by N.S.B. JavaScript & MathScript Interactive Document Generator version 001.

Introduction to N.S.B. JavaScript & MathScript Interactive Document Generator

JavaScript Data Types

Now that you know how to input and execute JavaScript code, let us examine some data types and some associated manipulations.

This sequence defines a number, examines and determines its type:

input(1)=> 3.45
output(1)=> 3.450
input(2)=> n=$() 
output(2)=> 3.450
input(3)=> typeof(n) 
output(3)=> number
input(4)=> isInt(n) 
output(4)=> false
input(5)=> isFlt(n) 
output(5)=> true

Notice that typeof() is a basic JavaScript function. On the other hand,the functions isInt() and isFlt() are defined by our program. The function isInt() checks to see whether the data type is an integer; the function isFlt() checks to see whether it is "float", which means it has a decimal point. There is another function isXpn(); this checks whether a number has exponential notation. Consider these:

input(6)=> c=speedOfLight; G=constGravity; m=mass('sun')
output(6)=> 1.989e+30

Many of the physical constants (such as speedOfLight and constGravity) and related functions (such as mass()) are already defined in the program. Let us first check the numeric types of these, without seeing them.

input(7)=> isNum(c)
output(7)=> true
input(8)=> isInt(c) 
output(8)=> true
input(9)=> isNum(G) 
output(9)=> true
input(10)=> isInt(G) 
output(10)=> false
input(11)=> isFlt(G) 
output(11)=> false
input(12)=> isXpn(G) 
output(12)=> true
input(13)=> isXpn(m) 
output(13)=> true

Let us verify the above statements by seeing our numbers. Putting them in a JavaScript array:

input(14)=> aa=[c, G, m]
output(14)=> [ 299792458, 6.673e-11, 1.989e+30 ]

Hence, we see that c is given as a whole integer; while G and m are given as exponential numbers.

Now that we have defined the above physical constants, let us compute the well-known Schwarzschild radius of the sun:

input(15)=> 2*G*m/pow(c,2)
output(15)=> 2953

Notice that all our physical quantities are given in the MKS or SI system of units. Hence the above radius is given in meters. The followings give the above result in kilometers, in miles, and in centimeters:

input(16)=> $(15)/kilo
output(16)=> 2.953
input(17)=> $(15)/mile 
output(17)=> 1.835
input(18)=> $(15)/centi 
output(18)=> 2.953e+5

We shall continue our exploration of JavaScript data type in the next document.

Next
NSB Cosmic Center Image

Home
N.S.B. Cosmic Center

NSB Cosmic Center Image