JS = JavaScript
He's a lightweight, other programming language.
Page code that can be inserted into HTML
After inserting an HTML page, it can be performed by all browsers now
Output statement: Document.writie ();
Declaring variables: Var eg:var A;
Assignment: = eg:a = 1;
JS data type: String numeric Boolean array object null undefined
String: var x = "Bill";
Number: var x = 5;
Boolean value: var x = true;
Array: var x = new Array ();
X[0] = "Music";
X[1] = "BMW";
X[2] = "Hello";
Or: Var cars=new Array ("Audi", "BMW", "Volvo");
var cars=["Audi", "BMW", "Volvo";
Object: var person={firstname: "Bill", LastName: "Gates", id:5566};
var person={
FirstName: "Bill,"
LastName: "Gates",
id:5566
};
Object properties are addressed in two ways, for example: Name=person.lastname;
name=person["LastName"];
Eg: <script>
var person={
FirstName: "Bill,"
LastName: "Gates",
id:5566
};
document.write (person.lastname + "<br/>");
document.write (person["LastName"] + "<br/>");
</script>
Undefined This value indicates that the variable does not contain a value.
Null indicates that the variable value is set to NULL
When declaring a new variable, you can use the keyword "new" to declare its type, for example:
var carname=new String;
var x= new number;
var y= new Boolean;
var cars= new Array;
var person= new Object;
JS Object
All things in JavaScript are objects: strings, numbers, arrays, dates, and so on. In JavaScript, objects are data that owns properties and methods.
Properties and Methods
A property is a value associated with an object.
Method is an action that can be performed on an object.
Create objects, such as:
Person=new Object ();
Person.firstname= "Bill";
Person.lastname= "Gates";
person.age=56;
Person.eyecolor= "Blue";
Here the person is the object, FirstName, LastName, age, Eyecolor are attributes, the right side of the equals sign is the value of the property
How do I access an object?
Syntax: Objectname.methodname ()
Function:
A function is an event-driven or reusable block of code that executes when it is invoked. Key words: function
Syntax: function functionname ()
{
Here is the code to execute
}
Note that function must be lowercase, and if onclick= "method name", then two of the function method name () must correspond.
Calling a function with parameters
When you call a function, you can pass a value to it, which is called a parameter. These parameters can be used in functions. You can also send any number of arguments, separated by commas (,): MyFunction (Argument1,argument2)
When declaring a function, declare the argument as a variable:
function MyFunction (var1,var2) {}
Variables and parameters must appear in a consistent order. The first variable is the given value of the first parameter passed, and so on. For example:
<button onclick= "myFunction (' Bil ')" > click here </button>
<script>
function MyFunction (name)
{
alert (name);
}
</script>
JavaScript provides multiple built-in objects, such as String, Date, Array, and so on.
To access the object's properties, syntax:
Objectname.propertyname
Methods for accessing objects
Methods are actions that can be performed on an object, and methods are invoked through the following syntax:
Objectname.methodname ()
There are two different ways to create a new object:
1 defining and creating an instance of an object
Person=new Object ();
Person.firstname= "Bill";
Person.lastname= "Gates";
person.age=56;
Person.eyecolor= "Blue";
2 Use a function to define an object, and then create a new object instance
function person (firstname,lastname,age,eyecolor)
{
This.firstname=firstname;
This.lastname=lastname;
This.age=age;
This.eyecolor=eyecolor;
}
"Learning Essays" JS initial involvement