JavaScript advanced Programming--Chapter III: Basic Concepts

Source: Internet
Author: User

JavaScript Advanced Programming--Chapter III: Basic Conceptsfirst, the grammar

EMCA-262 describes the basic concept of JavaScript implementation by "pseudo-language" called ECMAScript.

JavaScript draws on the syntax of C, is case-sensitive, the identifier begins with a letter, an underscore, or a dollar sign ($) , and the comment can be used // or/ * * /

Strict mode:

ECMAScript 5 introduces strict mode, where indeterminate behavior is handled in strict mode, and strict mode is enabled by adding "use strict" at the top:

function fuc () {    "use strict";
function Body}

This line of code is a compile prompt that tells JavaScript-enabled engines to switch to strict mode.

  Variable:

  The type of ECMAScript is loosely typed and can hold any type of data

Declare a variable by using var :

var message,      Num.      STR;

when you omit the var keyword, the global variable is created automatically.   
  Data type:

  Six types of data
1, Undefined
2, Null
3, Boolean
4. Number
5, String
6, Object (a set of unordered name value pairs)

  Operator: typeof Note is not a function that can be used for variables or numeric literals.
  
  Undefined:
The undefined type has only one value, that is, a special undefined,
When the variable definition is uninitialized, its value is undefined.
var    test;  typeof test = = "undefined"    //true
     Undefined is also returned when performing a typeof operation on an undeclared variable
  
  Null:
The value of the null type is NULL, which represents an empty object pointer,
    
The undefined value is derived from a null value.
typeof null = = ' object ';
If a defined variable is intended to be used to hold an object in the future, it is better to initialize the variable to null instead of the other value.
This allows you to know whether a variable has saved a reference to an object as long as it detects whether it is a null value.

  Boolean:
The Boolean type, with a value of true and false, is case-sensitive.
Any one of the data types to be converted to Boolean simply calls the Transform function Boolean ()
var msg = "Hello"; var msgtobool = Boolean (msg); True
Data type Convert to True Convert to False
Boolean True False
String Non-empty string "" Empty string
Number Not 0 digits 0 and Nan
Object Any object Null
Undefined Not applicable Undefined

The control leave statement (if) automatically performs the associated Boolean conversion.
  
Number:
    Use IEEE754 to represent integers and floating-point values,
    
var intnum =/           / integer var octnum = 020          // octal is not valid in strict mode, throws an error  var hexnum = 0xa          // hexadecimal arithmetic operations are converted to decimal values.
Numerical range number,min_value; Number.MAX_VALUE; Returns inifinity, cannot participate in the operation.

NaN
A non-numeric value (not a number) is a special value that is used in cases where an operand that would have returned a numeric value did not return a numeric value. For example, any value in ECMAScript will return nan in addition to 0.

    function isNaN () to determine whether the parameter is "not a numeric value";

IsNaN (NaN)   //true  IsNaN (//false converted to 10
    
IsNaN ("Blue")//true

numeric conversions


varnum = Parentint ("1234blue");//1234varnum = Parentint ("")//NaNvarnum = Parentint ("0xa")//Tenvarnum = Parentinr (22.5)// Avarnum = Parentint ("070")// Aboutvarnum = Parentint ("70")// -parsing octal ECMAScript3There's a disagreement with ECMAScript 5 .varnum = Parentint ("070")//3 ECMAScriptvarnum = Parentint ("070")//5 ECMAScriptThe second parameter specifies a cardinalityvarnum = Parentint ("AF", 16)//175varnum = Parentint ("AF");//NaN    

Parentfloat () converts only 10 binary.

 

JavaScript advanced Programming--Chapter III: Basic Concepts

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.