basiccodingconcept.online

What Are Data Types in Coding?

What Are the Different Types of Stuff Computers Store?

Blocks stack, dolls talk and cars race because each toy is a different type. Information in coding also comes in types and the type determines what a computer can do with that information. Computers need to know the type before they can work with any information.

Numbers

Store values used in counting, math and keeping score.

Strings

Store text like names, messages and game character names.

Booleans

Store only two answers: true or false.

Why Does a Computer Need to Know What Type Something Is?

A computer treats each type differently based on what it is. In coding, the type of data decides what operations are possible with that information. The number 5 and the text "5" look identical but behave differently inside a computer.

What Can Numbers Track and Calculate in a Program?

Numbers are used for counting, math, keeping score and tracking scores in programs. Decimals, such as a decimal temperature of 37.5, also fall under numbers, alongside whole numbers. Age and price store as numbers because computers perform calculations on them.

Numbers in video games track:

  • Coins collected (whole number)
  • Damage dealt to enemies (whole number)
  • Health points remaining (whole number)
  • Player level and rating (whole number)
  • Decimal temperature readings and score averages (decimal)

What Does a String Carry and How Does It Work?

Text in coding is called a string. A string requires quotes and is wrapped in quotation marks so the computer identifies the type correctly. Strings hold letters, names, messages and game character names.

String examples:

  • "Sarah" stores a name; a pet's name like Max also stores as a string.
  • "Good morning!" is a greeting string; the word morning inside it is made of letters.
  • "I love chocolate!" stores a favorite food statement as a string.

What Data Type Gives Only a Yes or No Answer?

A boolean represents yes/no questions in coding and is limited to two answers: true or false. Computers use booleans to store real-world states in video games and other programs.

isSunny = true
isLevelComplete = false
hasTreasure = true
canSwim = true
isTired = true

How Does a Computer Tell the Number 7 Apart From the Text "7"?

The number 7 and the number character "7" look identical, but a computer treats their type differently. When 7 is a number used for math: 7+7 equals 14. When that same value sits inside quotation marks as a string: "7" + "7" produces "77" instead.

Number math

7 + 7

= 14

The computer adds the values because both are numbers.

String joining

"7" + "7"

= "77"

The computer joins the text because both are strings.