JavaScript Basics 05

Source: Internet
Author: User
Tags pow

JavaScript Basics 05

1. Scope of variables

A variable can be either global or local.

Global variables: can be referenced anywhere in the script, once you declare a global variable in a script, you can

Referencing it anywhere in the script, including inside the function, the scope of the global variable is the entire script;

Local variable: exists only inside the function that declares it, cannot be used outside of the function, scope of the local variable

Limited to function interior only;

function Square (num) {        var total;        Total = num * num;        return total;    }    var total =;    Alert (total);    var number = square (a);    Alert (total);

2. JavaScript intrinsic functions

Some of the features in JavaScript are common, and they are provided to the user in the form of global functions called internal

Part function.

Parseint and parsefloat Convert a string to a number

3, Escape and unescape URL encoding and decoding

var url = "Http://www.baidu.com/s?name= millet";    url = Escape (URL);    alert (URL);    Alert (unescape (URL));

4. Objects

Avascript is an object-oriented language, so you can use object-oriented thinking to

JavaScript programming

An object is a data entity that is composed of some properties and methods that are related to each other.

Local objects

The 1.Date Date object is used to process the date and time. var mydate = new Date (); Mydate.getfullyear ();    Get the full year (4-bit, 1970-????) Mydate.getmonth ();       Get the current month (0-11, 0 for January) mydate.getdate ();        Get current day (1-31) mydate.getday ();         Get Current week x (0-6, 0 for Sunday) mydate.gettime ();        Gets the current time (the number of milliseconds starting in 1970.1.1) mydate.gethours ();       Gets the current number of hours (0-23) mydate.getminutes ();     Gets the current number of minutes (0-59) mydate.getseconds ();     Gets the current number of seconds (0-59) mydate.getmilliseconds ();    Gets the current number of milliseconds (0-999) mydate.tolocaledatestring ();     Gets the current date var mytime=mydate.tolocaletimestring ();     Gets the current time mydate.tolocalestring ();        Get Date and time    
The 2.Math object Math object is used to handle complex mathematical operations. The Math object is a global object of JavaScript and does not need to create math.abs ( -2) with new;           The method can return the absolute value of a number. Math.Round (5.5);      This method rounds a number to the nearest integer. Math.random ();      The method can return a random number between 0 (inclusive) ~ 1 (not included). Math.ceil (1.4);         The Ceil ()   method returns the smallest integer greater than or equal to X. (Take large whole) Math.floor (1.6);       The floor () method returns the largest integer less than or equal to X. (Take small whole) Math.pow (4,3);        The POW () method returns the Y power of X.  (4 of the 3-second party)

Job Title:

The simplest form and time package, write complex object-oriented, I am idle boring ah.

Are you a pig? Such a simple encapsulation function, write this what ghost.

<! DOCTYPE html>

<! DOCTYPE html>

JavaScript Basics 05

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.