- The instanceof operator returns a boolean value.
- The typeof operator return string value.
- The instanceof operator is used to check the type of an object at run time.
- The typeof operator is used to get the data type of its operand.
Code:-
- <!DOCTYPE html>
- <html>
- <head>
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <script>
- var ar = ["1", "2", "3"];
- function fun1()
- {
- alert(typeof ar);
- }
- function fun2()
- {
- var br = ["1", "2", "3"];
- var st = "Merin jojeriojdfoifdsg";
- alert("is String? : " + (ar instanceof Array).toString());
- alert("is Array? : " + (st instanceof String).toString());
- }
- </script>
- </head>
- <body>
- <button onclick="fun1();">typeof</button>
- <button onclick="fun2();">instanceof</button>
- </body>
- </html>
Instance of and type of :- JavaScript
Reviewed by Network security
on
November 13, 2019
Rating:
No comments: