aimnova.
DashboardMy LearningPaper MasteryStudy Plan

Aimnova site navigation

Stay in the loop

Get the latest study resources and updates

New features, study tips and exam insights — straight to your inbox.

IB Diploma

  • IB Past Papers
  • IB Study Notes
  • IB Question Bank
  • IB Mock Exams
  • IB Revision

IB Subjects

  • IB Math AA
  • IB Math AI
  • IB Economics
  • IB Business Management
  • IB Physics
  • IB Biology
  • View all IB subjects→

IB Past Papers

  • IB Math AA HL Past Papers
  • IB Math AA SL Past Papers
  • IB Math AI HL Past Papers
  • IB Math AI SL Past Papers
  • IB Economics HL Past Papers
  • IB Economics SL Past Papers
  • IB ESS Past Papers
  • View all past papers→

Study Resources

  • Study Notes
  • Question Bank
  • Mock Exams
  • Flashcards
  • Revision Guide
  • Exam Skills
  • Command Terms
  • Grade Calculator
  • Exam Timetable 2026

Aimnova

  • Features
  • Pricing
  • For Schools
  • For Parents
  • About Us
  • Blog
  • Contact
aimnova.

AI-powered study platform for smarter revision, past-paper analysis and examiner-style feedback.

TermsPrivacyCookies·© 2026 Aimnova. All rights reserved.8afc4e3

Aimnova is not affiliated with or endorsed by the International Baccalaureate Organization (IB).

NotesComputer ScienceTopic 6.1Variables and data types
Back to Computer Science Topics
6.1.15 min read

Variables and data types

IB Computer Science • Unit 6

AI-powered feedback

Stop guessing — know where you lost marks

Get instant, examiner-style feedback on every answer. See exactly how to improve and what the markscheme expects.

Try It Free

Contents

  • A named box holding a value
  • The five types
  • Local and global scope
  • Exam-style question
The big idea: A variable is a name for a place in memory holding one value.

Its data type says what kind of value that is — which decides both what can be stored and what can be done with it.
About the code in these notes: Paper 2 comes in a Python version and a Java version, and both ask the same questions.

The examples here are Python, with the Java equivalent named where it differs. The reasoning is identical in either.

Free preview

This is the free notes preview

You're reading the free notes. Aimnova Pro unlocks the full study experience — and you can try it with your first topic free to keep:

  • FlashcardsLock in vocabulary and key terms with spaced repetition.
  • Practice questionsAnswer exam-style questions and get instant AI marking.
  • Mock exams & past-paper vaultSit full mocks and see exactly how examiners award marks.
  • Personalised study planA daily plan built around your exam date and weak areas.
Start Studying Free Full access to Aimnova Pro · cancel anytime

Numbers

  • integer — a whole number: a count, an ID, a year
  • decimal — a number with a fractional part: a price, a measurement
  • Arithmetic works on both; dividing two integers may give a decimal

Text

  • char — a single character: 'A', '7', '?'
  • string — a sequence of characters: "Hello", "S1"
  • '7' the char is not 7 the integer — you cannot add 1 to it

True or false

  • Boolean — one of exactly two values: True or False
  • Produced by every comparison: x > 5 is a Boolean
  • What every if statement and every loop test actually uses
The same symbol, two meanings: + adds numbers and joins strings.

So "12" + "1" gives "121", while 12 + 1 gives 13. Mixing the two is one of the commonest bugs there is.

Feeling unprepared for exams?

Get a clear study plan, practice with real questions, and know exactly where you stand before exam day. No more guessing.

Get Exam Ready FreeYour first topic is free to keep • No credit card required
Where a variable can be seen: A local variable exists only inside the function that created it, and disappears when that function ends.

A global variable is created outside any function and can be seen throughout the program.

Local

  • Created inside a function
  • Cannot be seen or changed from anywhere else
  • Destroyed when the function ends
  • Two functions may safely use the same name
  • The default choice — it keeps effects contained

Global

  • Created outside any function
  • Visible throughout the program
  • Any function might change it, from anywhere
  • A bug can come from code you were not looking at
  • Use sparingly — for genuine settings and constants
Why globals cause hard bugs: If a value is wrong and it is local, the cause is in that function. If it is global, the cause could be anywhere in the program.

That difference is the entire argument for preferring local variables.

How this is tested — you must track each variable's value, and know where each one can be seen. It comes up two ways:

Paper 2 — working with code

  • Trace a program and state the output, 3-5 marks
  • Identify a variable's type, or a type error
  • Say why a variable is not visible where it is used

Paper 2 — the algorithmic-thinking question

  • Reason about scope with no code shown
  • Explain why a value did not change as expected
The classic trap: Assuming a function's change to a local variable is visible outside it. It is not — the local variable is destroyed when the function ends, and the outside value never moved.
IB-style questionTrace[4 marks]

State the output of this program and explain the final line.

total = 10

def bump(n): total = n + 1 return total

print(bump(4)) print(total)

Model answer plan

See the mark-by-mark plan — for / against / judgement, with marking guidance — in study mode.

Claim your free topic
IB-style questionTrace[4 marks]

State the output of this program and explain the final line.

int total = 10;

static int bump(int n) { int total = n + 1; return total; }

System.out.println(bump(4)); System.out.println(total);

Model answer plan

See the mark-by-mark plan — for / against / judgement, with marking guidance — in study mode.

Claim your free topic

Try an IB Exam Question — Free AI Feedback

Test yourself on Variables and data types. Write your answer and get instant AI feedback — just like a real IB examiner.

four data types commonly available in a programming language. [2 marks]

Related Computer Science Topics

Continue learning with these related topics from the same unit:

6.1.2Substrings
6.1.3Exception handling
6.1.4Debugging
6.2.1Static vs dynamic structures
View all Computer Science topics

Improve your exam technique

Command terms, paper structure, and mark-scheme tips for Computer Science

Previous
5.1.4Tracing flowcharts
Next
Substrings6.1.2

20 practice questions on Variables and data types

Students who practiced this topic on Aimnova scored 82% on average. Try free practice questions and get instant AI feedback.

Try 3 Free QuestionsView All Computer Science Topics