Home > Web Front-end > JS Tutorial > Chapter 1 of JavaScript for Beginners_Basic Knowledge

Chapter 1 of JavaScript for Beginners_Basic Knowledge

PHP中文网
Release: 2016-05-16 19:00:14
Original
1408 people have browsed it

The following are the things you should pay attention to when you first learn JavaScript (learned from <>)

JavaScript data types
Number: integer, floating point
String: character data, JavaScript does not distinguish between single characters and strings,
Any character or string can be enclosed in quotation marks or single Enclosed in quotation marks.
Boolean: Boolean type
Undefined: Undefined type, used for attributes of variables or objects that do not exist or have not been assigned an initial value, such as:
var name; the name at this time is Undefined
Null: Null value. Generally, Undefined and Null types are treated equally.
Function: Function. You can dynamically create the function with the required function through the new operator and the constructor Function(), and add functions to it. Body. For example:
var myFunction = new Function()
{
staments ;
} ;
Combined type: Array, Object
Array: Array type, including basic and combined data Sequence. Array is essentially an Array object.
var score = [56,34,23,76,45];
Object: Object type, the object is a combination type that can contain basic and combined data,
And the members of the object are used as attributes of the object, and the member functions of the object are used as methods of the object.

Operators in JavaScript:
The keyword corresponding to the null operator is "void", and its function is Define an expression, but the expression does not return any value.
Object operators: dot operator, new operator, delete operator, () operator.
typeof operator: used to indicate The data type of the operand, the return value type is a string. For example:
var myString = typeof(data);

with object operation statement: simplifies the reference process of object properties and methods, and its syntax structure As follows:
with(object)
{
statements ;
}

for...in: Perform loop operations on objects. For example:
for (variable name in Object name)
{
statements ;
}

Function: defined as follows:

function funcName([parameters])
{
statements ;
[return expression;]
}

Global functions: JavaScript defines many global (built-in) functions, which can be called directly during the programming process.
parseInt(): convert characters Convert strings to integers.
parseFloat(): Convert strings to floating point numbers.
escape(): Convert some special characters into ascii codes.
unescape(): Convert ascii codes into characters.

All data types, arrays, etc. in JavaScript scripting language can be treated as objects, and
functions are no exception. You can use the new operator and the constructor Function()
of the Function object to generate The basic syntax of a function that specifies rules is as follows:
var funcName = new Function(arguments,statements;);

JavaScript event processing:
JavaScript scripts can mainly handle events through anonymous functions, explicit
Anonymous function:
document.MyForm.MyButton.onclick=new Function()
{
alert("Your Have clicked me!");
}

Manual triggering:
Trigger an event through the methods of other elements without triggering the event through user actions, such as:





Relationship between top-level objects:
Open a The order of generating objects when creating a web page is: window->screen, navigator, location, history, frames[], document.

Objects in JavaScript:
The main objects in JavaScript are:
JavaScript’s core objects, browser objects, user-defined objects and text objects, etc.
As an object-based programming language, JavaScript’s object instances are created using constructors.
Each constructor includes an object prototype, defined The properties and methods contained in each object are shown. The object is dynamic, indicating that the
properties and methods of the object instance can be dynamically added, deleted or modified.

The object is defined through the construction method:


Method to directly initialize the object:
This method directly initializes the object The difference between initializing an object to create a custom object and defining the object's constructor method is that
this method does not need to generate an instance of the reference object. For example:


All objects in the JavaScript language are derived from the Object object. Each object has a prototype attribute that specifies its structure.
This attribute describes the code and data of this type of object. New attributes and new
methods can be dynamically added to the object through the object's prototype attribute.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template