Js data type
- JavaScript has five basic data types and three reference data types (complex data types).
- The simple data types are String, Number, Boolean, NULL, and Undefined.
- The referenced data types are Object, Function, and Array
Methods for detecting data types
- There are two common methods for detecting the data typeof a data, namely typeof and instanceof
- Typeof: Used to detect 5 simple data types, not complex data types.
- Instanceof: Used to detect complex data types.
- Test example:
console.log(typeof('abc')); //String console.log(typeof(123)); //Number console.log(typeof(true)); //Boolean console.log(typeof()); //NULL console.log(typeof(abc)); //Undefined console.log([] instanceof Array); // true console.log({} instanceof Object); // true console.log(function(){} instanceof Function); // true Copy the code