Skip to content
Lessons JSS 1 Digital Technologies Basic Computer Programming

Meaning, Types and Rules of Variables in Programming for JSS 1

Digital Technologies illustration
Study comfort0% read
Curriculum at a glance Your lesson roadmap Class, subject, theme and the learning goal for this lesson.
Class JSS 1
Subject Digital Technologies
Theme Basic Computer Programming
Topic Variables in Programming
Curriculum September 2025
Sequence 14
Learning outcome

Create programs using a visual programming language

Focal competence

Demonstrating efficiency and effectiveness in creating programs

ARTICLE CONTENTSOn this page 9 sections

Variables in Programming

Performance Objectives

By the end of the lesson, students should be able to:

  1. describe variables in programming;
  2. name variables;
  3. state the data types in coding;
  4. state the types of variables in coding;
  5. predict the outcome of a simple sequence that includes variables;
  6. trace the values of variables within a sequence;
  7. perform arithmetic operations on variables;
  8. identify increment decrement operator in a program.

Meaning of Variables

A variable is a named storage location in a computer’s memory used to hold data that can change during the execution of a program.

To understand variables, imagine a physical storage box. The box has a label written on the outside, which is the name of the variable. Inside the box, a single item or value is stored. If a new item is placed into the box, the old item is removed. In programming, the computer sets aside a small space in its memory to hold a value, and the programmer gives this space a specific name to easily find and change the value later.

Variables are essential in programming because they allow programs to be dynamic. Instead of using fixed values, a program can use variables to handle different information every time it runs. For example, a game program uses a variable to keep track of a player’s score, which increases as the player performs tasks.

Rules for Naming Variables

When creating variables in programming, certain guidelines must be followed to ensure the computer understands the code and other programmers can read it easily.

The standard rules for naming variables in programming include:

  1. Start with a letter or underscore: Variable names must begin with an alphabetic letter or an underscore character. They cannot begin with a number.
  2. No spaces allowed: Variable names must be a single continuous word. If a name contains multiple words, they can be joined using an underscore or camelCase.
  3. Use meaningful names: Names should describe the data being stored, making the program easier to understand.
  4. Do not use reserved keywords: Words that already have special meanings in the programming language, such as “if”, “repeat”, or “stop”, cannot be used as variable names.
  5. Avoid special characters: Symbols such as punctuation marks, brackets, or mathematical operators cannot be used within a variable name.

The table below shows examples of correct and incorrect variable names based on these rules:

Proposed Name Status Reason
player_score Correct Uses an underscore instead of a space.
playerScore Correct Uses camelCase to separate words.
2nd_player Incorrect Starts with a number.
player score Incorrect Contains a space.
total$ Incorrect Contains a special character ($).

Data Types in Coding

A data type is a classification that specifies what kind of value a variable can hold and what operations can be performed on it.

Computers process different kinds of information, such as numbers, words, and logical decisions. Specifying the data type helps the computer allocate the correct amount of memory and prevent errors during calculations.

The primary data types used in programming include:

  1. Integer: This data type represents whole numbers without any fractional or decimal parts. Examples include 15, -7, and 0.
  2. Float or Real: This data type represents numbers that contain decimal points. Examples include 3.14, -0.5, and 98.6.
  3. String: This data type represents text. It consists of a sequence of characters, letters, numbers, or symbols enclosed in quotation marks. Examples include “game_over”, “Player 1”, and “1234”.
  4. Boolean: This data type represents logical values that can only be either True or False. It is used to make decisions in programs.

Types of Variables in Block Coding

In block-based programming environments, such as Scratch, variables are classified based on where they can be accessed and modified within the program.

The two main types of variables in block coding are:

  1. Global Variables: These are variables that can be accessed and changed by any sprite or script within the entire project.
  2. Local Variables: These are variables that can only be accessed and changed by the specific sprite or script in which they were created.

A global variable is useful for sharing information across different parts of a program, such as a game score that affects multiple characters. A local variable is useful for tasks confined to a single character, such as tracking the speed of one specific moving object.

Observe the image below to see how these options are selected during variable creation in Scratch.

Operators in Programming

Operators are special symbols or blocks used to perform calculations, assign values, or modify variables within a program.

Arithmetic Operators

An arithmetic operator is a mathematical symbol used to perform calculations on numbers.

The standard arithmetic operators used in programming include:

  1. Addition (+): Adds two values together. For example, 5 + 3 results in 8.
  2. Subtraction (-): Subtracts one value from another. For example, 10 – 4 results in 6.
  3. Multiplication (*): Multiplies two values. The asterisk symbol is used instead of the traditional multiplication sign. For example, 4 * 3 results in 12.
  4. Division (/): Divides one value by another. The forward slash is used instead of the traditional division sign. For example, 20 / 5 results in 4.

Assignment Operators

An assignment operator is a symbol or block used to store a specific value inside a variable.

In text-based programming languages, the equals sign (=) is commonly used as the assignment operator. In block-based programming languages like Scratch, assignment is performed using a specific block, such as “set variable to value”. This operation overwrites any previous value stored in the variable with the new value.

Increment and Decrement Operators

An increment operator is an instruction that increases the value of a variable by a specific amount.

A decrement operator is an instruction that decreases the value of a variable by a specific amount.

In text-based programming, shorthand symbols like “++” (increment by 1) and “–” (decrement by 1) are often used. In block-based programming, the “change variable by value” block is used. To increment, a positive number is placed in the block. To decrement, a negative number is placed in the block.

Predicting Outcomes and Tracing Variables

Tracing is the process of manually stepping through a sequence of instructions to track how the values of variables change at each step.

This skill helps programmers find errors in their logic and predict exactly what a program will do before running it on a computer.

Consider the following sequence of instructions:

  1. Set score to 10
  2. Set bonus to 5
  3. Set total to score + bonus
  4. Change total by 2
  5. Change score by -3

To trace this sequence, a table can be constructed to record the value of each variable after each instruction is executed:

Step Instruction Value of score Value of bonus Value of total
1 Set score to 10 10 Undefined Undefined
2 Set bonus to 5 10 5 Undefined
3 Set total to score + bonus 10 5 15
4 Change total by 2 10 5 17
5 Change score by -3 7 5 17

By tracing the sequence, the final values of the variables are predicted as: score is 7, bonus is 5, and total is 17.

How to Perform Arithmetic Operations in Block Coding

This practical activity demonstrates how to create a simple program in Scratch 3.0 that uses variables and arithmetic operators to perform calculations.

The required materials are:

  1. A computer or tablet with Scratch 3.0 installed or accessed online.
  2. An active Scratch workspace.

The procedure involves the following steps:

  1. Open the Scratch 3.0 application or website.
  2. Navigate to the Variables category in the block palette on the left side of the screen.
  3. Click on the Make a Variable button.
  4. Type the name number1 in the dialog box, select For all sprites, and click OK.
  5. Repeat the process to create two more variables named number2 and sum_result.
  6. Navigate to the Events category and drag the when green flag clicked block into the workspace.
  7. Go back to the Variables category and drag two set variable to 0 blocks, placing them directly under the event block.
  8. Change the dropdown of the first set block to number1 and type 12 in the value input.
  9. Change the dropdown of the second set block to number2 and type 8 in the value input.
  10. Drag a third set variable to 0 block and snap it below the others, changing its dropdown to sum_result.
  11. Navigate to the Operators category and drag the green addition block ( ) + ( ).
  12. Go to the Variables category, drag the rounded number1 variable block, and drop it into the first empty slot of the addition block.
  13. Drag the rounded number2 variable block and drop it into the second empty slot of the addition block.
  14. Insert the combined addition block into the value slot of the set sum_result to block.
  15. Click the green flag above the stage to run the program.
  16. Observe the stage monitor to verify that sum_result displays the value 20.
Digital Technologies PRACTICE

Ready to test what you learned?

Check your understanding of Meaning, Types and Rules of Variables in Programming for JSS 1 with a quick, focused quiz and instant feedback.

20 questions · Instant results · Retake anytime
Quick practice
KEEP YOUR MOMENTUMNext in Digital Technologies
15of 27
Basic Computer Programming

Control with Conditions in programming

Keep the idea fresh by moving forward while it is still active in your mind.

Help another learner

Share this lesson

Know someone studying this topic? Send them this lesson so they can learn and practise too.

Community

0 comments

Open the discussion when you need it. Comments stay collapsed until requested so the initial article remains light.

Royal Alikor
About the author

Royal Alikor

Teacher/Educational Writer

Author profile →

Royal Alikor is an educator with six years of classroom teaching and three years of elementary school leadership experience and is still teaching. He develops and reviews practical, curriculum-aligned learning materials for Nigerian schools and teachers.

Reviewed byNnabugwu Onyenachiha PerpetualEducational Quality Assurance Director · Reviewed
Nigerian Basic and Senior Education Curriculum
1,367 published articlesSurePass editorial standards ↗

Share with