List of primitive data types in JS.
- String: represents a sequence of characters, enclosed in quotes (either single or double).
- Number: represents both integer and floating-point numbers.
- Boolean: represents a logical value of either
- Undefined: represents a variable that has been declared but has not been assigned a value. Example:
- Null: represents a variable that has been explicitly assigned the value of
let y = null;
- Symbol: represents a unique identifier that can be used as the key of an object property. Example:
const id = Symbol('id');.
Simple example code.
<!DOCTYPE html> <html> <body> <script> let message = "Hello, World!"; // String console.log(message) let age = 42; // Number console.log(age) let isStudent = true; // Boolean console.log(isStudent) let x; // Undefined console.log(x) let n = null; // Null console.log(n) const id = Symbol('id'); // Symbol console.log(id) </script> </body> </html>
Comment if you have any doubts or suggestions on this Js data type topic.
Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version
Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like learning technical.