A presentation on JavaScript's own objects and a brief introductory slide about JavaScript and its objects. Useful especially for GTU students pursuing computer or IT engineering.
3. Introduction to JavaScript, objects
JavaScript is the programming language of HTML and the Web.
JavaScript is used to program the behavior of web pages.
Web pages are not the only place where JavaScript is used. Many desktop and server
programs use JavaScript.
JavaScript variables are containers for data values. But objects can contain many values.
JavaScript objects are containers for named values called properties or methods.
E.g. var person = {firstName:“Ian", lastName:“Somerhalder", age:41, eyeColor:"blue"};
The name:values pairs in JavaScript objects are called properties.
Objects can also have methods.
4. JavaScript's own objects
JavaScript has its own objects. A good example of this is the Math object.
It has several properties and methods.
Properties such as PI are accessed as:
Document. Write(Math.PI); {if you want to print the value of PI}
The value PI is also known as a constant so it can’t be changed by assignment.
There are lots of useful methods attached to the Math object too.
They are accessed in a similar way:
myValue = Math.round(10.2);
These have brackets to contain values which are passed to the method.
10. Other methods of Math object
Math.sqrt(x) returns the square root of x.
Math.abs(x) returns the absolute (positive) value of x.
Math.ceil(x) returns the value of x rounded up to its nearest integer.
Math.floor(x) returns the value of x rounded down to its nearest integer.
Math.sin(x) returns the sine (a value between -1 and 1) of the angle x.
Sly we have Math.cos(x)
Math.min() and Math.max() can be used to find the lowest or highest value in a list of
arguments.
Math.random() returns a random number between 0 (inclusive), and 1 (exclusive).
12. Unlike other global objects, the Math object has no constructor. Methods and properties are static.
We also have other methods iike acos, asin, tan, atan, exp…