In programming, a primitive is a basic data type that is not an object and has no methods. In most programming languages, primitives are the building blocks for more complex data structures and are used to represent simple values like numbers, strings, and booleans.
Primitives are fundamental data types that are used to store simple values directly in memory. They are often stored more efficiently than objects because they do not require additional memory for methods or properties. Examples of primitives include integers, floating-point numbers, characters, and boolean values.
Example (JavaScript):
In JavaScript, there are six primitive data types: undefined
, null
, boolean
, number
, string
, and symbol
. Here are some examples of primitive values:
let age = 30; // number
let name = 'John'; // string
let isStudent = true; // boolean