1. Manipulating HTML elements
If you want to access an HTML element from JavaScript, you can use the document.getElementById (ID) method.
Use the ID property to identify the HTML element:
Example:
Access the HTML element with the specified ID and change its contents:
<! DOCTYPE html>
2. Arrays
The following code creates an array named cars:
var cars=new Array (); cars[0]= "Audi"; cars[1]= "BMW"; cars[2]= "Volvo";
or (condensed array):var cars=new Array ("Audi", "BMW", "Volvo");
3. Objects
Objects are separated by curly braces. Inside the parentheses, the properties of the object are defined in the form of name and value pairs (name:value). Attributes are separated by commas:
var person={firstname: "Bill", LastName: "Gates", id:5566};
The object (person) in the example above has three attributes: FirstName, LastName, and ID.
Spaces and lines do not matter. Declarations can span multiple lines:
var person={firstname: "Bill", LastName : "Gates", id : 5566};
4. Declaring variable types
When you declare a new variable, you can use the keyword "new" to declare its type:
var carname=new string;var x= new Number;var y= new Boolean;var cars= new Array;var person= new Object;
JavaScript variables are objects. When you declare a variable, a new object is created.
Small bet
All things in JavaScript are objects: strings, numbers, arrays, dates, and so on.
In JavaScript, objects are data that owns properties and methods.
5. Properties and Methods
A property is a value associated with an object.
Method is an action that can be performed on an object.
For example, a car is a real-life object.
Properties of the car:
Method of Car:
Car.start () car.drive () Car.brake ()
The properties of the car include name, model, weight, color, etc.
All cars have these properties, but the properties of each car are different.
The method of car can be start, drive, brake and so on.
All cars have these methods, but they are executed in different times.
6. Label
As you saw in the switch statement chapter, you can tag JavaScript statements.
To mark a JavaScript statement, precede the statement with a colon:
Break Labelname;continue LabelName;
Javascript Learning Notes One