[javascript]--Basic Learning

Source: Internet
Author: User
Tags arithmetic operators logical operators

JavaScript Overview

  The history of JavaScript

    • 1992 Nombas developed the embedded scripting language for C-minus-minus (c--) (originally bundled in Cenvi software). Rename it scriptease. (The language that the client executes)
    • Netscape (Netscape) received Nombas's philosophy, (Brendan Eich) developed a set of Netscape scripting languages in its Navigator livescript 2.0 product. Sun and Netscape are done together. And then the name is JavaScript.
    • Microsoft then emulated a JavaScript clone called JScript in its IE3.0 product.
    • To unify the three, the ECMA ( European Computer Manufacturing Association) defines the ECMA-262 specification. The International Organization for Standardization (ISO/IEC) also adopted ECMAScript as the standard (iso/iec-16262). Since then, Web browsers have struggled (albeit with varying degrees of success and failure) to ECMAScript as the basis for JAVASCRIPT implementations. ECMAScript is the norm.

  ECMAScript

  Although ECMAScript is an important standard, it is not the only part of JavaScript, and certainly not the only one that is standardized.

  The composition of JavaScript :

    • Core (ECMAScript)
    • Browser object models (BOM) Broswer object Model (integrated JS and browser)
    • The vast majority of Javascript in development is object-based. It is also object-oriented.

  To put it simply, ECMAScript describes the following: 

    • Syntax type
    • Statement
    • Key words
    • Reserved words
    • Operator
    • Object (encapsulates inherited polymorphism) object-based language. Use an object.
How JavaScript is introduced
{#1 write directly #}         <script>        alert (' Hello Yuan ')        </script> {#2 import file #}        <script sr C= "Hello.js" ></script>

two. The basics of JavaScript

2.1 Variables

X=5 y=6 z=x+y

In algebra, we use letters (such as x) to hold values (such as 5).

By the above expression Z=x+y, we can calculate the value of Z as 11.

In JavaScript, these letters are called variables.

0 variables are weakly typed (very casual);

  1 Declare a variable without declaring the variable type. All use the var keyword;

var A;

2. A row can declare multiple variables. And can be of different types.

    var name="yuan", age=20, job="lecturer";

3. If Var is not used when declaring a variable, then this variable is a global variable

4. Variable names can only start with a letter, underscore, or $ character, and are case-sensitive

5. Variables should also adhere to one of the following well-known naming conventions

    

The first letter of the Camel notation is lowercase, and the next letters begin with uppercase characters. For example:  var mytestvalue = 0, Mysecondvalue = "Hi" = 0, Mysecondvalue = "Hi" = 0, Smysecondval UE = "HI";

2.2 Basic Specifications

1. each line ends with a semicolon. No semicolon will end with a newline character as each line

a=1;b=2;

    A=1 b=2;------ Error

    A=1

b=2-----Correct    

2. Comments, support multi-line comments and single-line comments/* *//

3. Use {} to encapsulate a block of code

2.3 Constants and identifiers

Constants: Data values that appear directly in the program

Identifier:

1. Consisting of letters, numbers, underscores, and $ not beginning with numbers

2. Commonly used to represent functions, names of variables

3. A word that represents a specific meaning in theJavaScript language is called a reserved child and does not allow the program to be customized as an identifier

2.4 Data types

   Brief introduction

The most basic type of data

No distinction between integral and floating-point values

All numbers are stored in 64-bit floating-point format, equivalent to the double format in the Java and C languages

The maximum value that can be represented is the minimum value ±1.7976931348623157 x 10308 can represent is ±5 x 10-324

Integer:

10 integers in JavaScript consist of sequences of numbers
What is the exact range of the expression?-9007199254740992 (-253) to 9007199254740992 (253)
Integer out of range, accuracy will be affected

Floating point number:
Using decimal points to record data
Example: 3.4,5.6
Use Index to record data
Example: 4.3e23 = 4.3 x 1023

16 binary and 8 decimal expressions
16 binary data front plus 0x, octal front plus 0
16 binary numbers are made up of 16 characters, such as 0-9,a-f
8 binary number consists of 0-7 and 8 digits
16 binary and 8 binary and 2 binary conversion

# 2 binary: 1111 0011 1101 0100   <-----> 16 binary: 0xf3d4 <-----> 10 binary: 624201 111 001 111 010 <-----& Gt 8 binary: 0171724

Strings (String)

Introduction is a sequence of string constants consisting of Unicode characters, numbers, and punctuation marks the end of a single quotation mark or double quotation mark in a JavaScript in which there is no character type common special characters in the string expression string in a part special characters must add the right dash common escape character \ n: line break  \': Single quote   \ ': double quote  \ \: Right Dash

Use of the string data type

    • How to use special characters and their effects
    • How Unicode is inserted
<script>        var str= "\u4f60\u597d\n Welcome to \" JavaScript World \ "";        alert (str); </script>

Boolean Type (Boolean)

Introduction The Boolean type has only two values: True and False, also representing 1 and 0, true =1 in the actual operation,false=0 Boolean value can also be consideredon/off, yes/no, 1/ 0 corresponds to true/falseA Boolean value is primarily used for JavaScript control    statements, such as if (x==1) {    y=y+1;    }  Else    {    y=y-1;    }

Null & Undefined
"Undefined"null

NULL derived, so ECMAScript define them as equal. Although the two values are equal, they have different meanings. Undefined is the value that is assigned to a variable when it is declared but not initialized,null

typeof operator, this is simply described in this article). If the function or method is to return a
NULL . var person=New person ()var person=Null

Data type conversions

++ + Boolean: Boolean conversion to string true or False

Coercion type conversion function

function parseint:   cast to integers   such as parseint ("6.12") =6  , parseint ("12a") =12, parseint ("A12") =nan  ;p arseint (" 1a2 ") =1 function parsefloat: Cast to floating-point number  parsefloat (" 6.12 ") =6.12 function eval:       cast the string to an expression and return the result eval ( "=2"); Eval ("1<2") =true

type query function (typeof)

ECMAScript provides the typeof operator to determine whether a value is within a certain type of range. You can use this operator to determine whether a value represents an original type: if it is the original type, you can also determine which primitive type it represents.

Boolean / object) such as typeof ("test" +3)      "string" such as typeof (null)          "Object" for example typeof (true+ 1)        " Number " for example typeof (true-false)    " number "

ECMAScript operatorECMAScript arithmetic operators
Add (+), subtract (-), multiply (*), divide (/), remainder (%)  Add, subtract, multiply, divide, remainder, and mathematical methods  for example: 9/2=4.5,4*5=20,9%2=1-In addition to representing a minus sign can also represent a negative sign  such as: x=-  Y+ In addition to the connection that can be used to represent addition operations for strings  such as: "ABC" + "def" = "abcdef"

Increment (+ +), decrement (--)

If x=2, then the X + + expression after the execution of the value of the 3,x-- expression after the execution of the value of 1i+ + equivalent to i=i+1,i--equivalent to the i=i-1 increment and decrement operator can be placed before the variable can also be placed after the variable:--I     var i=1; Console.log (i+ +); Console.log (+ +i); Console.log (i--); Console.log (I.);

Unary Plus subtraction:

varA=1; varB=1; A=-a;//A=-1    varC= "10"; Alert (typeof(c)); C=+c;//Type ConversionsAlerttypeof(c));//    -------------------    varD= "Yuan"; D=+D; alert (d);//nan: A special value of type number that gets a NaN data when it encounters an invalid transfer stringAlerttypeof(d));// Number    //nan Features:        varn=NaN; Alert (n>3); Alert (n<3); Alert (n==3); Alert (n==NaN); Alert (n!=nan);//all of the operations that Nan participates in are false, except! =

ECMAScript logical operators
Equal to (= =)  , not equal to (! =), greater than (>), less than (<)? greater than or equal to (>=), less than or equal (<=) with (&&), or (| |), non-(!) && 1 = 1  1 | | 1 = 1&& 0 = 0  1 | | 0 = 1&& 0 = 0  0 | | 0 = 0!0=1!1=0

Logical AND Operator (&&)

        

[javascript]--Basic Learning

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.