JavaScript can specify a set of rules for the browser to follow which enables it to access or modify the content of a page. For example, you can create a script that check which image a user clicked on and display another image or open up another link. Besides, you can create a calculator that collects inputs from a user and display the results. You can learn how to create many wonderful scripts by following our lessons here.
Author: Liew Voon Kiong
Looping in JavaScript
In JavaScript Looping is a procedure whereby the execution is repetitive and will only terminate until a certain condition is met. There are two types of loops, the for loop and the while loop.
Math Object
Math object is an important JavaScript object because it can be used to perform web-based mathematical calculations. It can compute data input by the user and then displays its output on the web page. It is very useful for programmer to design online applications that involve calculations and games. We will see examples that use Math object in later lessons. These are various methods and properties of the Math object which we can use to perform mathematical calculations.
Declaring Variables in JavaScript
What is a variable in JavaScript? A variable is something that store values or information. The values can be numbers (numeric values), text (strings) or any other information such as dates, boolean values(true/false) and more. These values can change from time to time, that is why the name variable. It is similar to the post boxes in the post office, the contents of the post boxes can change but the post boxes still have the same name or label.
To declare a variable in JavaScript, we can use the keyword var
The basic structure of value assignment in JavaScript is
var variable_name= value
or
variable_name= value
The Date Object in JavaScript
We have learned about the document object in previous article. In this article, we will learn about the date object in JavaScript.The date object is used to manipulate and display date and time. Like the document object, the date object also has methods. The Methods associated with the date object are getDate, getDay, getHours, getMinutes, getSeconds, getYear and more. Each of these methods returns the current time value associated with the method name. For example, getDate will return the current while get minutes will return the current minutes
In order to use the Date object, we need to create an instant of the object using the New keyword.