/ Published in: JavaScript
                    
                                        
Basic usage of the in and instanceOf operators.
                
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
function operators(){
//Use of in Operator
var o = {x: 1, y: 2};//Create object
var haveX = "x" in o;//true
var haveY = "y" in o;//true
var haveZ = "z" in o;//false
var haveMethod = "toString" in o;//true (inherited property)
console.log(haveX, haveY, haveZ, haveMethod);
var a = [1, 2, 3];
var check1 = a instanceof Array;//true
var check2 = a instanceof Object;//true (array is an object)
var check3 = a instanceof RegExp;//false
console.log(check1, check2, check3);
var d = new Date();
var check1 = d instanceof Date;//true
var check2 = d instanceof Object;//true
var check3 = d instanceof Number;//false
console.log(check1, check2, check3);
}
Comments
 Subscribe to comments
                    Subscribe to comments
                
                