Basic js and basic js tutorials
Js introduction:
Js (JavaScript) is a type of original scripting language that thoroughly targets objects while interpreting and executing. HTML (Hypertext Markup Language) connects multiple objects on a web page to interact with web customers. JavaScript applications must be downloaded to the browser client, both on the client and on the server, thus reducing the burden on the server. Its features are summarized as follows.
- JavaScript is mainly used to add interactive behaviors to HTML pages.
- JavaScript is a script language syntax similar to java
- JavaScript is generally used to write client scripts.
- JavaScript is an explanatory language that can be interpreted and executed.
ECMAScript, a JavaScript component:
ECMAScript is an open and internationally accepted standard scripting language specification. It is not bound to any specific browser. The ECMAScript standard mainly describes the content.
- Syntax
- Variables and Data Types
- Logical control statement
- Keywords, reserved words
- Object
Browser Object Model
Browser Object Model (BOM) provides an Object that interacts with the Browser window independently of the content. You can use BOM to interact with HTML.
Document Object Model
Document Object Model (DOM) is a set of standard methods defined in the HTML Document Object Model. It is used to access and operate HTML documents.
JavaScript variables and Data Types
JavaScript is a weak type language with no explicit data type. That is to say, when declaring a variable, you do not need to specify its type. The type of the variable is determined by its type.
Syntax for declaring variables: var valid variable name = value;
Data Type:
- Undefined: undefined type (indicating that the variable has no initial value)
- Null: null type (a placeholder that does not exist at all. It can be used to detect whether a variable is assigned a value. The undefined value is actually derived from null, so JavaScript defines them as equal)
- Number: numeric type (including integer and decimal)
- String: String type
- Boolean: Boolean Type
Common Methods for String objects
- ToString (): returns a string.
- ToLowerCase (): converts a string to lowercase.
- ToUpperCase (): replace string with uppercase
- CharAt (index): returns the character at the specified position
- IndexOf (str, index): searches for the position of a specified string that appears for the first time in the string.
- Substring (index1, index2): returns the string between the specified index index1 and index2 (including index indexes excluding index2)
- Split (): Splits a string into a string array.
Array
Array: a set of one or more values of the same data type. The array uses a name to store a series of values and uses subscript to distinguish each value in the array. The subscript of the array starts from 0.
Model:
1 <script type = "text/javascript"> 2 var array = new Array (4 ); // define an array with four lengths. 3 // assign the first two values to the array. 4 array [0] = 1; 5 array [1] = 2; 6 // output array Item 7 alert (array [0]); 8 </script>Common methods and attributes of model Arrays
Attribute:
Length: sets or returns the number of elements in the array.
Method:
- Join (): Put all elements of the array into a string, which is separated by a separator.
- Sort (): sorts arrays.
- Push (): Add one or more elements to the end of the array and return a new length.
Custom functions:
Syntax:
Function Name (parameter ){
JavaScript statement;
Return Value]
}
Call:
Event name = "function name ()";