Getting Started with JavaScript classic Redbook read Note 6.13

Source: Internet
Author: User
Tags control characters

I'm used to using Word to publish my blog post, but I've found a problem, which is that when you hit a piece of code in Word, all the parts of the code change color, and the mouse moves over the hyperlink effect, even though it's not linked to anything.

So I do not have a paragraph of the code in this note, anyway, now look at the data type JS and variable, JS although some special, but the data types and variables are some of the things, there is no code to knock.

The Red Book says the most commonly used are numeric types, character types, and Boolean types. It was then explained in detail.

2.1.1 Numeric data

numeric data has both integers and fractions, and fractions are also called floating-point numbers.

Although in use, integers and floating-point numbers can be treated as different types, but in fact, JS treats them as floating-point types (poor integers ...). ). JS naturally hides the exact details of the transitions in between, so this is usually not a problem to consider. An exception to this is that when a floating-point number needs to be converted to an integer, the floating-point number needs to be rounded before it can be converted to an integer.

2.1.2 Text data

We typically refer to text that contains one or more characters as a string, and in JS, the string is the text in a paragraph (""). Strings can also be enclosed in single quotation marks.

JS contains many special characters that cannot be entered directly, and they are represented by the series of escape characters. An escape character series is a series that consists of a backslash (\) plus a character.

See here I want to go to see NetEase Micro Professional video, I remember a chapter seems to specifically talk about this. Well...... Yes, I also reported NetEase's front-end development engineer micro-professional. But I still do not like to watch video recording to learn, so or to see the main document.

But I was wrong again ... NetEase front-end micro-professional does not explain the escape character JS, I remember that is actually the HTML entity characters, two different. Although the symbols are represented by strange sequences. As Red Book writes, the escape character of JS differs depending on the character set, such as the Latin-1 escape character series and the Unicode escape character family, but some commonly used escape characters are generic. Like what:

\b Backspace

\ f Change page

\ nthe line break

\ r Enter

\ t tab

\ ' Single quotation mark

\ "Double quotation marks

\ \ Backslash

I wondered for a moment, what is the difference between a newline character and a carriage return character?

Now the answer is this:Enter\ rThe original meaning is that the cursor is back to the bankRof Englishreturn, control characters can be writtenCR, i.e. Carriage Return
line Break\ nThe original meaning is the cursor down a line (not necessarily to the next line at the beginning),Nof EnglishNewLine, control characters can be writtenLF, i.e.Line Feed

2.1.3

Boolean data ... As if there is no note to do, only know JS directly using Ture and false.

2.2 variable--data stored in memory

In the JS code, the variable name is case-sensitive.

In addition, some specific words or characters cannot be variable names. These specific words are the reserved words in JS, reserved words are JS reserved for their own use. You can use a number in the variable name of JS, but the number cannot be the beginning of a variable name.

2.2.1

Before using a variable, the variable should be declared with the keyword VAR, after declaring the variable, JS will tell the computer to reserve the appropriate memory space to store the variable's data. Semicolons are used to denote the end of a JS statement.

once a variable is declared, you can use a variable to hold any type of data, and in many strongly typed languages, declaring a variable not only requires declaring the variable name, it also requires declaring the variable's type at the same time. However, JS is a weakly typed language, and it has no strict restrictions on the types of data that variables can hold. (Wow, I'm so happy to see this place, I've never understood the strong-type language.) Why do you want to declare the type, and feel useless? )

We can think of variables as a box, a box for storing items, and how to store content in variables.

We use the "=" number to store the contents of the variable, looking at the following statement:

var mynum = 5; Declares a variable mynum and assigns a value.

How do you pronounce this statement? Assigns a value of 5 to the variable mynum. We can also write this:

var mynum; Declaring variable Mynum

Mynum = 5; Assigning values to variable Mynum

Note: the function of "=" Here is to assign a value to a variable, not an equal number.

The box can be loaded with clothes, toys, fruits ... such as In fact, a variable is an omnipotent container, and you can store anything in a variable, such as a value, a string, a Boolean, and so on, for example:

var num1 = 123; 123 is the value

var num2 = "123"; "123" is a string

var num3=true; Boolean True (True), False (False)

Where the content stored by the NUM1 variable is numeric, the content stored by the num2 variable is a string, the string needs to be enclosed in a pair of quotation marks "", and the content stored by the NUM3 variable is a Boolean value (True, false).

--Quote from MU-net

When you assign a new value to a variable, the original value of the variable is lost forever. In JS, a process called garbage collection will automatically release memory that is no longer in use. What is the difference between language and language in the end? So far I can't understand it. When JS detects that a variable is no longer in use, or if a variable that references an object is given a new value, it will automatically run garbage as a process to free up the memory used by those variables.

2.2.2 assigning values to variables with other variables

This looks at the title to know the content, there is no note to do so.

Getting Started with JavaScript classic Redbook read Note 6.13

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.