Learn the basics of front-end JAVASCRIPT-1 and JavaScript starting from scratch

Source: Internet
Author: User
Tags script tag

1:definition: javascript is a weak-type, dynamic-type, interpreted scripting language.

Weak type: The type check is not strict, preferring to tolerate implicit type conversion.

strongly typed: the type check is strict and is biased towards non-tolerance of implicit type conversions.

Dynamic Type: performs type checking at run time.

static type: when compiling, you know the type of each variable.

Interpretation: The program does not need to compile, the program is translated into machine language when running, every time to translate once, so the efficiency is low, but good cross-platform.

compiled: The program needs a special translation process before execution, the program is compiled into machine language files, the runtime directly use the results of the compilation is OK.

Markup Language: the existence of markup language is used to be read (browse), and its own incapacity, in the markup language you will see < and > These angle brackets, which is used to write "hierarchy" and "attribute", in other words, it is passive. Does not have the ability to interact with visitors.

programming Language: It is logical and behavioral, which is active. To be popular, it is thoughtful.

scripting language: It is between the markup language and the programming language, the scripting language does not need to compile, can be used directly, by the interpreter to be responsible for interpretation.

2:JS History

1) Netsape invented JavaScript.

2) JS's father Brendan Eich (Brandon Aichi)

3) Why is it called JavaScript ?

4) JS is not related to the Java language

5) JS Standardized---ECMAScript

3:JS Composition

4:File Introduction

<script> tags are used to define client script. It can contain either a script statement or an external script file through the SRC attribute.

Property:

language: used to specify the type of script in the <script> tag, which is JavaScript. deprecated , most browsers have ignored it, so do not use it.

Type : It is also used to specify the type of script in the <script> tag, i.e. Text/javascript. It is also the default value for type, so you can omit the specified.

src: Specifies the external script file. If this attribute is specified, the script tag contains the JS scripts that are not executed.

You cannot use a single label, which is <script type= "Text/javascript"/>.

1) Introduction of external files

<script type= "Text/javascript" src= "JS file" ></script>

2. stored in HTML

<script type= "Text/javascript" >    JS Code content </script>
    • In the head of HTML
    • The bottom of the body code block of HTML ( recommended )

3) Why put it at the bottom of the <body> code block?

    • HTML code from top to bottom execution, first load CSS, to avoid HTML appearance without style state;
    • Put the JavaScript code block in <body> Finally, can let the Web page as soon as possible to the user, reduce the waiting time of the browser, avoid because JS block blocks the rendering of the page.
5:js notesannotations can be used to improve the readability of your code. JavaScript does not execute annotations, and the user does not see comments, which simply make it easier for developers to understand the JS code.

Single-line comment: starts with//.

This is a single line of comments

Multiline Comment: starts with/* and ends with */.

/* First line comment second line comment */

Document comments: start with/** and end with */.

/** This is a comment for the document */

  

Important Note: to/*! Start with the */End

/*! This is a very important comment */
6:JS Variable

Variables are containers for storing information, and variables are declared (created) with the Var keyword.

1) Variable definition (declaration):

Define the post-assignment value first:

var age; var is the keyword, and age is the variable name

Age = 20; 20 is the data "=" is an assignment

simultaneous assignment of definitions: var age=20;

Declare multiple variables in one statement, which begins with Var and is separated by commas.

var x= ' addend ', y= ' addend ', z= ' and ';

2) Local variables must be declared with VAR, or global if no var is written

<script type= "Text/javascript" >      //global variable    name = ' Xiaoming ';      function func () {        //local variable        var age =;          global variable        sex = "man"    }</script>

Note: 1, variables can also not be defined, but strongly not recommended. 2, the variable must be assigned first and then used

7: variable naming rules and common naming methods

1) Variable naming rules: consists of letters, numbers, underscores, and $, but cannot begin with a number. and the JS and JS variables are strictly case-sensitive . You cannot use pinyin to name it.

2) variable commonly used nomenclature recommended Spanish nomenclature, with lowercase letters b,f,i,s beginning to denote type, followed by uppercase beginning of meaningful words.

Camel : The first letter is lowercase, followed by the first letter of a word.

Pascal's Nomenclature (Pascal): capitalize the first letter of all words.

Hungarian Nomenclature (Hungarian): adds the appropriate lowercase letter to the first name of the variable to identify the type of the variable, followed by the initial capitalization of the word.

Hump naming method//var havegoodgoods = ' good goods ';//Pascal nomenclature//var havegoodgoods;//hungarian nomenclature//var shavegoodgoods = ' Good goods ';

3) try to use meaningful words as variable names (semantically), and try not to conflict with keywords in HTML or CSS.

Keep a list of keywords

Learn the basics of front-end JAVASCRIPT-1 and JavaScript starting from scratch

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.