Intern
What data types exist in JavaScript?
sobes.tech AI
Answer from AI
In JavaScript, there are eight data types:
Primitive types:
- null: represents the intentional absence of any object value.
- undefined: indicates that a variable has not been assigned a value.
- boolean: a logical type, can be
trueorfalse. - number: a numeric type for both integers and floating-point numbers.
- bigint: for working with large integers beyond the
numberlimit. - string: a sequence of characters.
- symbol: a unique and immutable primitive type, often used as object keys.
Non-primitive:
- object: a complex data type used to represent collections of data and more complex entities. Includes arrays (
Array), functions (Function), objects (Object), etc.
Examples:
// null
let emptyValue = null;
// undefined
let notAssigned;
// boolean
let isLoggedIn = true;
// number
let age = 30;
let price = 19.99;
// bigint
let largeNumber = 1234567890123456789012345678901234567890n;
// string
let name = "Alice";
// symbol
const id = Symbol('id');
// object
let person = { name: "Bob", age: 25 };
let numbers = [1, 2, 3];
function greet() { console.log("Hello"); }