Basic JavaScript Data Structure

Source: Internet
Author: User
The programming of the scripting language provided by JavaScript is very similar to that provided by C ++. It only removes common errors such as pointers in the C language and provides a powerful class library. for people who already have C ++ or C, it is very easy and pleasant to learn the JavaScript scripting language. i. Category C... syntaxHighlighter. al JavaScript provides scripting language programming which is very similar to C ++. It just removes the pointer errors in C language and provides a powerful class library. for people who already have C ++ or C, it is very easy and pleasant to learn the JavaScript scripting language. 1. JavaScript code is included in HTML, which is part of the HTML document. combined with HTML tags, it forms a powerful Internet programming language. you can directly add JavaScript scripts to the document: script language = "JavaScript"> JavaScript language code ;.... /script> Description: Mark the script>... script indicates that the source code of the javascript script will be placed in it. the attribute Language = "JavaScript" is used to describe the Language used in the logo. Here is the JavaScript Language, which indicates the Language used in JavaScript. the following is an example of adding a JavaScript script to a Web document: Test2.html html> head> script language = "JavaScript"> document. write ("this is a network school"); document. close ();/script>/head>/html> call test2.html in the browser window to display the string "this is a network school. see. description: Document. write () is the output function of the document Object. Its function is to output the characters or variable values in brackets to the window. document. close () is to close the output. script>... put the script identifier into head> ..OrBetween.../body>. Place the javascript identifier...Load the code between the header before the home page and other parts of the Code to make the code more powerful; you can place the javascript mark in... /Body> dynamically creates documents between subjects. 2. Similar to other languages, the basic data type JavaScript scripting language has its own basic data types, expressions and arithmetic operators, and the basic framework structure of the program. javaScript provides four basic data types for processing numbers and text. While variables provide places where information is stored, expressions can complete complicated information processing. 1. The basic data types are four basic data types in JavaScript: Numeric (integer and real), string (character or value enclosed by "" sign or ), boolean (expressed by True or False) and null. data in the basic JavaScript type can be constants or variables. javaScript uses a weak type, so a data variable or constant does not need to be declared first. Instead, it determines the data type when using or assigning values. of course, you can also declare the Data Type first. It automatically describes the data type when assigning values. 2. constants Integer constants JavaScript constants are also called literal Constant, which cannot be changed. the integer constant can be expressed in hexadecimal notation, octal and decimal notation. A real constant is represented by an integer plus a decimal number, for example, 12.32 or 193.98. it can be represented in scientific or standard methods: 5E7, 4e5, etc. A boolean constant has only two States: True or False. it is mainly used to describe or represent a state or sign to describe the operation process. it is different from C ++. C ++ can use 1 or 0 to indicate its state, while JavaScript can only use True or False to indicate its State. one or several characters enclosed by single or double quotation marks (') or double quotation marks. for example, "This is a book of JavaScript", "3245", "ewrt234234", etc. null JavaScript has a null value, indicating that nothing exists. if you try to reference a variable without definition, a Null value is returned. the special characters are the same as those in C language. JavaScript cannot be displayed if they start with a backslash (/). Special characters. it is usually called a control character. 3. Variable variables are mainly used to access data and provide containers for storing information. for a variable, you must specify the name, type, declaration, and scope of the variable. the name of A variable in JavaScript is very similar to that in the computer language. Note the following two points: A must be A valid variable, that is, the variable starts with A letter, numbers such as test1 and text2 can appear in the middle. except for the underscore (-), the variable name cannot contain spaces, (+), (-), (,), or other symbols. b. JavaScript keywords cannot be used as variables. more than 40 class key words are defined in JavaScript. These keys are used internally in JavaScript and cannot be used as variable names. for example, Var, int, double, and true cannot be the variable name. when naming a variable, it is best to match the meaning of the variable with its meaning to avoid errors. the type of the variable is in JavaScript. The variable can be declared using the command Var: var myt Est; this example defines a mytest variable. but no value is given to it. var mytest = "This is a book" This example defines a mytest variable and assigns its value. in JavaScript, variables can be unspecified, and the type of variables is determined based on the data type during use. for example, x = 100 y = "125" xy = True cost = 19.5. x integer, y is the string, xy is the boolean type, and cost is the real type. the declaration of variables and JavaScript variables in their scopes can be declared and assigned values before use. declare variables by using the var keyword. the biggest benefit of declaring variables is the ability to detect errors in the code in a timely manner. Because JavaScript uses dynamic compilation, it is not easy to find errors in the Code, especially the variable naming. there is also an importance for variables-that is, the scope of the variables. global variables and local variables are also available in JavaScript. A global variable is defined outside all function bodies and has a scope of effect. Is the whole function, while the local variable is defined in the function body, only visible to the function, and invisible to other functions. 3. Expression and operator 1: After the expression defines the variables, it can assign values, change, and calculate them, this process is usually called an expression. It can be said that it is a set of variables, constants, Boolean and operators. Therefore, expressions can be divided into arithmetic expressions, string expressions, value assignment expressions and boolean expressions. 2. A series of symbols used by operators to complete operations. In JavaScript, there are arithmetic operators such as +,-, *,/, and comparison operators such! =, =, Etc.; there are logical boolean operators such! (Reverse), |, |, and has string operations such as +, + =. in JavaScript, there are binary operators and single-object operators. the binary operator consists of the following: operand 1 operator operand 2 is composed of two operands and an operator. for example, 50 + 40, "This" + "that", etc. A single object operator requires only one operand, and its operator can be in front or back. (1) Arithmetic Operators in JavaScript include single and binary operators. binary operators: + (plus),-(minus), * (multiplication),/(except), % (Modulo), | (by bit or ), & (bitwise AND), <(left shift), >>( right shift), >>> (right shift, zero fill ). single Object OPERATOR:-(inverse ),~ (Complement), ++ (increment 1), -- (decrease 1 ). (2) The basic operation process of the comparison operator is to compare its operands and then return a value of true or False. There are eight comparison operators: (less than),> (greater than), <= (less than or equal to), >=( greater than or equal to), ==( equal ),! = (Not equal to). (3) added several boolean operators in JavaScript :! (Inverse), & = (and post-assignment), & (logical and), | = (or post-assignment), | (logical or ), ^ = (assign values after XOR), ^ (logical XOR ),? (Three-object operator), | (OR), = (equal to), | = (not equal to). The main format of the Three-object operator is as follows: operand? Result 1: result 2 if the result of the operand is true, the result of the expression is result 1; otherwise, result 2 is displayed. 4. The following is a JavaScript document on the effect of a lawn lamp. test2_1.html html> head> script Language = "JavaScript"> var msg = "This Is A JavaScript document for running horse lights"; var interval = 100; var spacelen = 120; var space10 = ""; var seq = 0; function Scroll () {len = msg. length; window. status = msg. substring (0, seq + 1); seq ++; if (seq> = len) {seq = spacelen; window. setTimeout ("Scroll2 ();", interval);} else window. setTimeout ("Scroll ();", interval);} function Scroll2 () {var out = ""; for (I = 1; I = spacelen/space10.length; I ++) out + = space10; out = out + msg; len = out. length; window. status = out. substring (seq, len); seq ++; if (seq> = len) {seq = 0 ;}; window. setTimeout ("Scroll2 ();", interval);} Scroll ();/script> body>/html>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.