November 25, 2016, using the morning time to learn JavaScript data types and variables, the afternoon should go to the library to bubble books.
After reading this chapter of the variable , I may not be able to finish the day, so I'll use the morning and evening nine o'clock to come back. Adjust the mentality, do not ask for speed, just quality, learn can, maybe I am the next js big God/laugh/laugh/Steal laughter
2.1 and get the following small example:
Code Explanation:
2.1.1 Var myfirstvariable; At this time the value of the variable is undefined, for the computer, the variable declaration merely indicates the existence of the variable, and does not hold any actual data in it, but underfined is indeed a basic value in JS, You can also use this value to compare. For example, you can use the undefined value to check whether a variable contains an actual value, and if it does not contain any actual value, its value is undefined
2.1.2 Myfirstvariable = "Hello"; literal value: The actual data, not the values obtained from other variables or after calculation. In any place where numeric literals or string literals are used, you can replace them with a variable that contains a numeric value or a string.
2.1.3 myfirstvariable = 54321;
2.2 Assigning values to variables with the values of other variables
Copy of data: As a general rule, basic data types, such as String types and numeric types, replicate a separate copy of the data as they are assigned.
Other complex data types, when copied, refer to the same object instead of copying an object copy.
2.3 Setting up the browser to display error messages
Allows the browser to display errors in the code itself
In Firefox
2.4 Working with data-basic operations for calculating numeric values and strings
The three alert in the code is loaded with a value of 1.5.
In most cases of JS, variables are used to calculate. Even if you calculate with a variable, a value, and a variable, and then save the result in another variable. For the use of literal calculations such as 15/10, it is best to first calculate the value of the expression and write it directly into the code. Instead of letting JS calculate the value of an expression 5/10, write 1.5 directly in the code. This will not aggravate the burden of JS, making it more and more slow speed. This benefit can also make your code more readable. We can also assign the expression to a variable and use the variable name to express the value, for example, per kilogram of units assigned to the variable priceperkg, so that the code will be easier to read and understand.
2.5 self-increment and decrement operators
The following is a special understanding
Operator:--、 + +, + =
Precedence of the 2.6 operator
Get the following small code
Code: Degfahren is not assigned, but instead prompts the user to enter a value using the prompt () function. The use method is similar to the alert () function but contains a text box for the user to enter a numeric value, in addition to prompting the user for information. The values entered by the user are saved in the variable Degfahren. The return value of the prompt () function is a string that can be used as a value, and JS will implicitly convert it to the corresponding value.
Prompt () requires two parameters: 1, the string to display, usually to remind the user of the information entered
2. When the prompt dialog box pops up, enter the default values that are included in the box
Two parameters are separated by commas and given in the order specified. If you do not need to set the default value for the input box when the prompt dialog box pops up, set the second parameter to an empty string "".
2.7 Basic manipulation of strings
Get the code as follows:
Three variables are defined, and the second is a string that is entered for the user in the prompt dialog box
The third variable is not initialized
The Document object is used to represent a Web page, and it has a variety of properties, such as bgcolor. You can also use the document.write () method of the Document object to write strings or HTML tags directly in a Web page. Simply pass in the string you want to write to the Web page as a parameter to the document.write () method.
2.8 Mixed string and numeric operations
You can mix data and strings in an expression. The previous temperature conversion was simply to show the converted number, without the user explaining its meaning. We can add some descriptive text in front of the number to illustrate its meaning. For example: "The value converted to degrees Centigrade is 10. "(The Fahrenheit temperature is converted to 10 degrees Celsius)
The following example is with the 2.6 demonstration
Code:
Alert (Degfahren + "\xb0 Fahrenheit is" + degcent + "\xb0 centigrade"); The alert () function contains an expression, Degfahren, that contains a numeric value.
2.9 Conversion of data types
Usually used in a form, so you need to concatenate two strings to sum them. A function that converts a string to a numeric type: the parseint () function and the parsefloat () function
The code is as follows:
Effect:
Learning to get started with JavaScript (ii)