Skip to content

Commit 9ab0352

Browse files
feat: add type operators
1 parent be42de4 commit 9ab0352

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

part1 (Basics)/18_type.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Type Operators in JavaScript
2+
3+
/*
4+
typeof Returns the data type of a variable or expression.
5+
instanceof Checks if an object is an instance of a constructor.
6+
in Checks if a property exists in an object.
7+
*/
8+
9+
// typeof
10+
console.log(typeof 42); // Output: "number"
11+
console.log(typeof 'hello'); // Output: "string"
12+
13+
// instanceof
14+
console.log([] instanceof Array); // Output: true
15+
console.log({} instanceof Object); // Output: true
16+
17+
// in
18+
const person = {name: 'Alice', age: 25};
19+
console.log('age' in person); // Output: true
20+
console.log('salary' in person);// Output: false

0 commit comments

Comments
 (0)