Skip to main content

Variables, explained.

Published 2021/09/06 09:00

What is a VARIABLE in programming?

Variables are one of the basic building blocks of any program, app or website, no matter the programming language.

So what are they?

Let's explain!

Variables in programming are essentially a way of storing information that may be used later within the program.

This information could be text, numbers, dates of a list of items.

Suppose you write a program. You want this program to give a personalised welcome message to your user, by using their name.

A great way to do this is by storing the user's name as a variable. You can then use that variable to display the welcome message.

For example, this is a common way to store a text variable (for example, a name) in Javascript:

var name = "Savvas"

As you may have noticed, variables are usually declared using a name on the left side, then an equal sign, followed by the actual value of the variable.

Some more info may be needed depending on the language (such as var for "variable" in Javascript)

So you could then use it to display a welcome message to your user:

var name = "Savvas"

console.log(`Welcome ${name}`)

This is especially useful, when you ask your user to type their name:

var name = prompt("Hello! What is your name?")

console.log(`Welcome ${name}`)

Using variables, you could also store numbers:

var age = 35

Lists of items:

var friends = [
    "Savvas",
    "Alice",
    "Bob"
]

And many more types of data. How you declare variables will depend on the programming language you're using.

This is how you declare a variable in Python:

name = "Savvas"

Java:

String name = "Savvas"

(notice that you need to specify what type of data your variable is storing. String basically means text)

In conclusion, variables are the way for your program to store information that will be used later. Whether text, such as the name of your user, a number, such as the age of your user, a list of items, such as a list of names, and many other types of data.

Thanks for reading!

Dev, Explained (43 part series)

  1. Javascript Scopes, explained.
  2. Javascript Promises, explained.
  3. Accessibility, explained.
  4. React, explained
  5. Should I use forEach() or map()?
  6. Should I use Flexbox or CSS Grid?
  7. Docker, explained.
  8. Unit testing, explained
  9. Git, explained.
  10. Typescript, explained.
  11. async/await, explained.
  12. The DOM, explained.
  13. Regular expressions, explained
  14. GraphQL, explained.
  15. Vue, explained.
  16. Svelte, explained.
  17. API, explained.
  18. Javascript Hoisting, explained.
  19. Immediately Invoked Function Expressions (IIFE), explained.
  20. ARIA roles, explained.
  21. Test-driven Development, explained.
  22. ARIA live regions, explained.
  23. aria-label in accessibility, explained.
  24. Type coercion in Javascript, explained.
  25. Variables, explained.
  26. if statements, explained.
  27. Arrays, explained.
  28. Currying in Javascript, explained.
  29. Memoization, explained.
  30. For loops, explained.
  31. Javascript Prototypes, explained.
  32. React Hooks, explained.
  33. Graph databases, explained.
  34. MongoDB, explained.
  35. Serverless, explained.
  36. Javascript Callback functions, explained.
  37. HTML, explained.
  38. CSS, explained.
  39. Responsive design, explained.
  40. Javascript, explained.
  41. The CSS Box Model, explained.
  42. CSS Flexbox, explained.
  43. CSS Grid, explained.
2022 Savvas Stephanides
Buy me a coffee
Some icons from Freepik