Eloquent JavaScript #

Source: Internet
Author: User

When action grows unprofitable, gather information; When information grows unprofitable, sleep. Ursula K. Le Guin, the left Hand of Darkness

Index
    1. Several viewpoints of the author

    2. ECMAScript Standard

    3. Values, Types, and Operators
    4. Web browsers is not the only platforms in which JavaScript is used. Some databases, such as MongoDB and CouchDB, use JavaScript as their scripting and query language.

This tutorial should be continuously updated, the author says in Introduction that the book uses the 2017 version of JavaScript

copy↓

keeping programs under control is the main problem of programming.

The art of programming is the skill of controlling complexity.

Some programmers believe that this complexity was best managed by using only a small set of well-understood techniques in t Heir programs. They has composed strict rules ("best practices") prescribing the form programs should has, and carefully stay within th Eir Safe Little Zone.

This isn't only boring, it's also ineffective. New problems often require new solutions. The field of programming is young and still developing rapidly, and are varied enough to the same as wildly differen T approaches. There is many terrible mistakes to do in the program design, and you should go ahead and make them so this you understand T Hem. a sense of the What a good program looks like was developed in practice, not learned from A list of rules.

Standard ECMA-262-ECMA International

After it adoption outside of Netscape, a standard document is written to describe the the-the-the-JavaScript language should Work, so and the various pieces of software that claimed to support JavaScript were actually talking about the same lang Uage. This was called the ECMAScriptStandard and after the ECMA international organization that did the standardization.

Values, Types, and Operators

  1. Bits
  2. Values -

    Each value must be stored somewhere, and if you want to use large amounts of data at the same time, you may be running out of memory . Fortunately , this is a problem only when you need a lot of value at the same time. As long as you no longer use the value, it disappears, leaving a part of it as a building material for next-generation values.

    This chapter describes the atomic elements of JavaScript programs, which are simple value types and operators that can handle these values .

  3. Numbers-JavaScript uses fixed-length bits to store digital---JavaScript USes a fixed number of bits, namely of them, to store a single number value. Can Represe Nt 264different numbers, which is on quintillion (an-with-zeros after it). Only 2 of 64 times a different number of words!  does not refer to so many positive integers. ---- - not all whole numbers bel ow quintillion fit in a JavaScript number, though. Those bits also store negative numbers, so-one bit indicates the sign of the number. A bigger issue is this nonwhole numbers must also be represented. To do This, some of the bits is used to store the position of the decimal point. The actual maximum whole number so can be stored are more In the range of 9 Quadrillion (zeros)-which is still pleasantly huge.

  4. Special Numbers -the first double ARe Infinity -Infinity and, WHICH represent the positive and negative Infiniti Es. Infinity - 1is still Infinity . Don ' t put too much trust in infinity-based computation, though.     It isn ' t mathematically sound, and it'll quickly leads to our next special number: NaN . --------------- NaN stands for ' Not a number ', Even though it is a value of the number type. You'll get this result when you, for example, try to calculate 0 / 0 (zero divided by zero), or any number of Infinity - Infinity oth ER numeric operations that don ' t yield a meaningful result.

  5. Strings,too, have to being modeled as a series of bits to being able to exist inside the computer. THe-is JavaScript doES This was based on the Unicode standard.This standard assigns a number to virtually every character you would ever need, including characters from Greek, Arabic, Japanese, Armenian,And so on .  If we have a number for every character, a string can is described by a sequence of numbers. ---'/n '--- and that's what JavaScript does. But there's a complication:javascript ' s repre sentation u ses-bits per Str ing element, which can describe up to 216different characters. B ut Unicode d e fin es more cha racters t Han That-about twice as many, at T His point. So some characters, such as many emoji, tak e up '
  6. unary operators ----not all operators is symbols. Some is written as words. One example is the  typeof  operator, which produces a string value naming the type of the value you Give it. This refers to a non-symbolic unary operator Typeof→  console. 4.5) output =  number

  7. Comparison---ther E is only one v alue In JavaScript, which is not equal to itself, and that is  NaN   (' not a number ').   console. log (NaN Span class= "Cm-operator" >== nan)   //→false   ------ -  NaN  is supposed to denote the result of a nonsensical computation, and as such, it isn ' t equal to the result of any  ; other  nonsensical computations.

  8. Empty Values -don't confuse it with special numbers, it's out of the category of numbers (numbers).

    There are two special values, written as null and undefined, to denote missing values (that is, meaningless values). They are values themselves, but they do not contain any information.

    There are many operations in the language that do not get meaningful values (see later) that produce undefined because they must produce some values. ↑ (although not containing any information)

    The difference in meaning between undefined and null is an unexpected part of JavaScript design, and most of the time it doesn't matter. in cases where you have to pay attention to these values, I would consider them to be broadly interchangeable.

Empty Values # Pick

There is special values, written and null undefined , that is used to denote the absence of a meaningful valu E. They is themselves values, but they carry no information.

Many operations in the language so don ' t produce a meaningful value (you'll see some later) yield undefined simply because t Hey has to yield some value.

The difference in meaning between undefined null and are an accident of JavaScript's design, and it doesn ' t matter most of the Time. In the cases where you actually has to concern yourself with these values, I recommend treating them as mostly Interchang Eable.

Automatic Type Conversion # pick

Rue. When you don't want any automatic type conversions to happen, there is both additional operators: and === . The first tests whether a value is precisely equal to the other, and the second tests whether it's not precisely Equal. So is "" === false false as expected.

I recommend using the Three-character comparison operators defensively to prevent unexpected type conversions from Trippin G You up. But if you're certain the types on both sides would be the same, there are no problem with using the shorter operators.

We can use the this functionality as a by-fall back on a default value. If you have a value of that might is empty, you can put after || it with a replacement value. If the initial value can be converted to false, you ll get the replacement instead. The strange technique of logical operation

Another important property of these, operators is, the part to their right is evaluated only when necessary. true || Xin the case of, no matter what X is-even if it's a piece of program that does something terrible -the re Sult would be true, and is X never evaluated. The same goes false && X for, which is false and would ignore X . This is called short-circuit evaluation.

The conditional operator works in a similar. Of the second and third value, only the one which is selected is evaluated.

Eloquent JavaScript #

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.