Skip to main content

Data Type

In Turkish
Veri türü
Updated 2 min read

Share this page

Send the link, quote the definition with a link back, or show it as a card on your own site.

https://softwaredictionary.org/terms/data-type

In short

A data type is a classification that tells a program what kind of value a piece of data holds, such as a number or text, and which operations work on it.

What is a data type?

A data type describes what kind of value something is and which operations make sense for it. You can add two numbers or join two pieces of text, but multiplying a date by a sentence has no meaning. Every value in a program, whether it is stored in a variable, passed to a function, or returned from one, has a data type.

Most languages provide a small set of built-in primitive types, such as integers, floating-point numbers (numbers with decimals), strings (text), and booleans (true or false). On top of these, they offer composite types that group several values together, such as arrays, objects, and classes. In JavaScript, the typeof operator reveals a value's type while the program runs: typeof 42 returns "number", and typeof "hi" returns "string".

Data types work like the shapes of electrical plugs and sockets: a plug only fits the sockets designed for it, which stops you from connecting things that don't belong together. Languages differ in when they check types. Statically typed languages such as Java, C#, Rust, and TypeScript check types before the program runs, while dynamically typed languages such as JavaScript and Python check them while it runs.

Static versus dynamic typing is often confused with strong versus weak typing. Static and dynamic describe when types are checked, while strong and weak describe how strictly a language refuses to mix types automatically. JavaScript is dynamic and fairly weak, so "5" + 1 quietly produces "51", while Python is dynamic but strong and raises a TypeError for the same operation.

Key takeaways

  • A data type defines what kind of value data holds and which operations are allowed on it.
  • Common primitive types include integers, floating-point numbers, strings, and booleans.
  • Composite types such as arrays and objects group several values together.
  • Static typing checks types before the program runs; dynamic typing checks them while it runs.

Example

Primitive and composite types in TypeScripttypescript
// Primitive types
const age: number = 30;
const userName: string = "Ada";
const isAdmin: boolean = false;

// A composite type built from primitives
type User = { name: string; age: number; isAdmin: boolean };
const user: User = { name: userName, age, isAdmin };

console.log(typeof age); // "number" (checked while the program runs)
console.log("5" + 1);    // "51": the number is converted to text

// const total: number = "10"; // Error: Type 'string' is not assignable to type 'number'

Readers ask

What are primitive data types?

Primitive data types are the simplest built-in types a language provides, such as numbers, strings, and booleans, which are not made up of other values. JavaScript has seven: string, number, bigint, boolean, undefined, symbol, and null.

What is the difference between static and dynamic typing?

In a statically typed language, types are checked before the program runs, usually by a compiler, so many mistakes are caught early. In a dynamically typed language, types are checked while the program runs, which is more flexible but lets type errors slip through until that code actually executes.

Why is 0.1 + 0.2 not equal to 0.3?

Most languages store decimal numbers as binary floating-point values, which cannot represent some fractions, like 0.1, exactly. The tiny rounding errors add up, so 0.1 + 0.2 gives 0.30000000000000004; for money, use whole numbers such as cents or a dedicated decimal type.

See also

Spotted a mistake or something missing on this page?Suggest an edit

Read a random page
Open today's review
Switch to the dark theme
Read this page in Türkçe

More

Settings