JavaScript Basics (i)

Source: Internet
Author: User
Tags logical operators

JavaScript Basics (a) What is JavaScript
    • Page-based scripting language
    • Lightweight
    • can be inserted into HTML
    • Basically, all browsers support
    • Completely different from Java
Label

The browser executes the script inside the tag.

<script></script>
Position

This script is habitually placed underneath the head or inside the body.
But more still in a single file, and then import the file

<script src="myScript.js"></script>
Looking for a certain ID

JavaScript determines the specific label by looking for an ID in the HTML

document.getElementById("demo").innerHTML="我的第一段 JavaScript";

The above code can replace the original contents of the demo tag with "My first JavaScript."

document.write("<p>我的第一段 JavaScript</p>");

The above code prints a paragraph to the screen, note! It can only be used when the page has just been loaded, and will overwrite the page if it is loaded.

Branch

Semicolons are optional for Javascrip

Function

Functions need to be added in front of function

function functionName(){}
Code line Wrapping

Not recommended, you can use \ Wrap between strings

Comments

The comments are exactly the same as the C/////* *

Variable

Use Var to declare variables

Array
var a = new Arry(‘q‘, ‘w‘, ‘e‘, ‘r‘)
Object oriented

JavaScript is an object-oriented language, and all variables are objects

var person={firstname : "Bill",lastname  : "Gates",id        :  5566}

Recommended when working with properties in an object

person.firstname

Recommended when working with methods in an object

person.eat()
Calling functions

Many tags can be added onclick= "MyFunction ()"
This allows you to call functions

return value

function can be returned without specifying a function type

Operators, comparators, logical operators

+-*,%<>= = = = >= <= && | | !
The meanings of all symbols are the same as ordinary

Basic statement

if () {}else{}
Switch () {case1:break;default:break;}
for (;;)
While
Break;continue;
Try throw catch

Form validation

Use ID to read value for further verification
Alert () can output a warning
Console.log () can print logs

JavaScript Basics (i)

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.