JavaScript Basics Section

Source: Internet
Author: User

JS Basics

JavaScript is the most popular scripting language in the world, especially now, with computers, mobile phones, tablets and countless H5-based mobile apps, the interactive logic is written in JavaScript.

JavaScript is an interpreted type of programming language that runs in a browser.

Features: cross-platform, cross-browser, and Java basically no matter ...

JS is a weakly typed language, and its type is implicitly converted when the variable is operating, such as:

var a = 12; var b = ' Console.log ' (a+b) Result: ' 1212 ' type is string

Netscape released JavaScript in 1995.

ECMAScript is the standard, JavaScript is specifically implemented

ES6 released in 2015.6 months

It is common to put JavaScript code in the head tag, or you can import the. js file by importing it as follows

<script src= "path or link" ></script>

In this it is recommended that you use an imported

Grammar

The statement is best to use a semicolon; end

Variable assignment: var x = 1;

Code block with {...}

if (2>1) {x = 1;   y = 2; }

If statements in other languages can be used in a nested

Comment://comment content (single line)/* * ... */Multiline comment

variables

1) This variable is a global variable if it is defined without the var keyword

2) It is recommended to use variable nomenclature: var imytestvalue = 123 I means this is an integer variable, the string is in front plus s

3) The first character can only be letters, underscores, $ symbols, case-sensitive

4) cannot be a keyword

650) this.width=650; "Width=" "height=" 823 "title=" 877318-20161020152532717-389530735.png "style=" WIDTH:596PX; height:238px, "src=" Https://s3.51cto.com/wyfs02/M02/96/A9/wKiom1kkHpeghwdCAAOMaY27kIg986.png "alt=" Wkiom1kkhpeghwdcaaomay27kig986.png "/>

Data Type

Integers and floating-point numbers 12;3.14;-321;1.5e3 are not distinguished in number:js ... All are number types

Nan:not A number note: Nan = = Nan is False IsNaN (Nan); The result is: true

Infinity: denotes infinite size

String: ' abc ', ' 123 ' and so on are all strings

Boolean value: False, True (in Python: true, False)

Note: The result of ' + ' > 3 is False, comparing the ASCII value of ' 2 ' in ' 25 ' with the ASCII value of ' 3 '

Logical Operations

&&: With arithmetic true && true result is true && false result is false

|| : or Operation false | | True result is true

! : Non-op! True result is False

comparison Operation

>, <, >=, <=, = = (auto-convert data type and compare), = = = (absolute equals, does not convert type)

Note: 1/3 = = = (1-2/3); The result is: false because the floating-point number generates errors during the operation

null and undefined

Null means an "empty", not the same as 0 and an empty string, undefined means undefined, which is declared, but is assigned

Array

An array is a set of sequentially arranged sets, each of which is called an element

[1,2,999, ' Hello ', null,true] is an array of type

You can also create an array by using the new array (all-in-a-.)

Array elements can be accessed by indexed values

Data type Conversions

JavaScript is loosely typed programming language
Variable does not need to specify a data type when declaring
Variable determines the data type only when it is assigned
The inclusion of different types of data in an expression forces class conversions to occur during the calculation


Number + string: number converted to string
Number + Boolean: True converts to 1,false to 0
String + Boolean value: Boolean converted to string true or False

Forcing type conversions

function parseint: Cast to integer such as: parseint ("6.12") = 6

Parsefloat: Cast to floating point

Function eval: Cast the string to an expression and return the result (same as Python) eval ("+") = 2

self-increment, decrement operator

i++: First refer to the value of I, then I self-increment 1,++i just the opposite

I--、 and I.

JavaScript Basics Section

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.