Scope of the variable
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 reference it anywhere in the script (including inside the function), the scope of the global variable is the entire script;
local variable : only exists inside the function that declares to it, cannot use it outside the function, the scope of local variable is limited to inside function;
Cases:
function Square (num) {var total;total = num * Num;return total;} var total = 50;alert (total), var number = square (); alert (total);
Variables declared in the function with VAR are defined in the function, but are not declared with VAR as the global variable is defined in the function, and the local variable is declared with Var
JavaScript intrinsic Functions
Some of the features in JavaScript are very common, and they are provided to the user as global functions, which are called intrinsic functions.
1.eval ()
Eval takes a string-type argument, executes the string as code in the context, and returns the result of the execution;
var i = 1;eval ("i = i + 1"), eval ("alert (i);");
2.parseInt and parsefloat Convert a string to a number3. 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:
1. Date Date objects are used to process dates and times.
varMyDate =NewDate (); 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 since 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 ();//Get Current datevarMytime=mydate.tolocaletimestring ();//Get current TimeMydate.tolocalestring ();//get date and time
2.Math objects
The Math object is used to handle complex mathematical operations.
The Math object is a global object of JavaScript and does not need to be created with new
Math.Abs (-2); 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 the big 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)
Scope of variables, JavaScript intrinsic functions