JavaScript学習の使用

2592 ワード

弱いタイプのプロパティ#
var num1 = 66;
var num2 = "66";
num1+num2 = "6666";
num1-num2 = 0;
num2-num2 = 0;

データ型
number、string、boolean、null、undefined、object。            。
object  ,Function、Date、Array……。

タイプ変換
typeofオペレータ
typeof "John"                 //    string 
typeof 3.14                   //    number
typeof NaN                    //    number
typeof false                  //    boolean
typeof [1,2,3,4]              //    object
typeof {name:'John', age:34}  //    object
typeof new Date()             //    object
typeof function () {}         //    function
typeof myCar                  //    undefined (   myCar     )
typeof null                   //    object,         ,     null,            。

constructorオペレータ
"John".constructor                 //      String()  { [native code] }
(3.14).constructor                 //      Number()  { [native code] }
false.constructor                  //      Boolean() { [native code] }
[1,2,3,4].constructor              //      Array()   { [native code] }
{name:'John', age:34}.constructor  //      Object()  { [native code] }
new Date().constructor             //      Date()    { [native code] }
function () {}.constructor         //      Function(){ [native code] }

instanceofオペレータ
instanceof         , :
var a = {};
alert(a instanceof Object);  //true
var b = [];
alert(b instanceof Array);  //true
instanceof           ,             ,  
var b = '123';
alert(b instanceof String);  //false
alert(typeof b);  //string
var c = new String("123");
alert(c instanceof String);  //true
alert(typeof c);  //object
  , instanceof           

try-catchネスト
  
try  
{  
    document.forms.input.length;  
}  
catch(exception)  
{  
    alert("try    "); 
    try  
    {  
        document.forms.input.length  
    }  
    catch(exception2)  
    {  
        alert("catch    ");  
    }  
}  
finally  
{  
    alert("  finally"); 
}  
 
     :try    》》》catch    》》》  finally

JSの厳格モード
     JavaScript          ,           ,          ,       。

     :            'use strict'
  :
1.     with,    SyntaxError
2.            
3.arguments         
4.delete  、   ,  SyntaxError;delete          ,  TypeError
5.             SyntaxError, var o = {a:1,b:2};
6.         , console.log(0123);
7.eval     
8.eval、arguments     ,      、