JavaScript basic operation and principle learning

Source: Internet
Author: User
Tags object object

 /* Temporary Object Test JS in the temporary object after the reference will be destroyed */function OnClick () {var s= "Hello World"; var word=s.substring (S.indexof ("") +1,s.length); alert (word); var s= "Test"; s.len=4; Console.log ("s.len=:", S.len);//output: undefined var t=s.len;//alert (t); var t=s.len=4;console.log ("s.len=", t);// 4console.log ("s.len=", S.len);//undefinedvar s= "test", B=1,c=true;var s=new String (s), var b=new number (b); var c=new Boolean (b); Console.log ("s", s),//== s and s are the same, and when = = = All equals, the two are different because S is a string type and S is an object. Console.log ("IsTrue", S===s?true:false);//falseconsole.log ("IsTrue", S==s?true:false);//trueconsole.log ("s", typeof (S));//stringconsole.log ("s", typeof (S)), the original value in//object//js cannot be changed, not in any case, if other methods are called, he will regenerate A// The value of the object can be changed by var h= "Hello"; Console.log ("ToUpper", H.touppercase ());//"Hello" Console.log ("H", h);//"Hello" var o={x:1}; Console.log (typeof (O)); Console.log ("o.x", o.x); O.x=2;console.log ("o.x", o.x); o.y=3;//creates a new property for object o and assigns a value of Console.log ( "O.x", o.x); Console.log ("O.y", o.y); var a=[1,2,3];a[0]=0;a[3]=4;//object is a reference type, in any case assigning A to B, the object itself is not copied once, it is simply an assignment referenceValue, personal understanding: This assignment is the same base address, so they are congruent. var a=[];var b=a;b[0]=1;console.log (A[0]) console.log ("IsTrue", A===b?true:false); Typechange ();} function Typechange () {var s=10+ "objects";//10 converted to string var sum= "7" * "4";//two are converted to numbers; var n=1-"x";//=>nan, character "X" cannot be converted to a digital console.log (n); n+= "Objects";//=>objects cannot be converted to a digital console.log (s,sum,n);}     function Ondown () {/* Various types convert to String tostring () */var b=new Boolean (false);     Console.log ("B", b); Console.log ([1,2,3].tostring ());//1,2,3 Console.log ((function (x) {f (x);}).     ToString ());//function (x) {f (x);} Console.log (New Date (2017,0,1). toString ()),//sun Jan 00:00:00 gmt+0800//ValueOf () convert to actual     The image does not return the original value */var ob={x:1};     Console.log ("ob=", Ob.valueof ())//ob= [Object Object] var d=new Date (2017,1,9);     Console.log ("d==", d.valueof ());//1486569600000 converted to 1970 since JS's internal representation value in milliseconds represents the date var a=checkscope ();     Console.log ("Checkscope:", a);} Scope= "glocal"; function Checkscope () {//scope= "local";//myscope= "local"; Console.log ("Scope ", scope);//return [Scope,myscope];} /* Eval () has the ability to change global variables, but when it is called by the definition alias, Eval executes the string as the top-level global variable. That is, if an alias is used in a function to perform an eval on a global variable, the code executed will define a new global variable and global function, or assign a value to a global variable, but cannot use or modify the local variable in the keynote function, so it does not affect the optimization within the function. Personal understanding: When using aliases to manipulate global variables, the return of global variables within a function does not change, or is called a new global variable, and the global variable itself executes the method of manipulating the global variable in the function as the top-level global variable, so the function returns the global variable unchanged, but the global variable itself changes.   */var Geval=eval;   var x= "Global", y= "global"; function f () {var x= "local"; Eval ("x+= ' changed ';");   return x;} function g () {var y= "local"; Geval ("y+= ' changed ';");   return y;} Console.log (f (), X),//localchanged Global Console.log (g (), y);//local globalchanged</script>

JavaScript basic operation and principle learning

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.