C#
In C#, a variable declaration follows this format:
🤖 Pseudocode
<DATA_TYPE> <NAME> = <VALUE>;
<DATA_TYPE>: The type of value the variable will hold (e.g., number, text, boolean).<NAME>: A recognizable name for the variable.<VALUE>: The initial value to store (optional; a variable can also be declared without an initial value).
// An integer variable named score with the initial value of 0. int score = 0; // A string variable named username with the initial value of "Ze". string username = "Ze"; // A boolean variable named named isAlive with the initial value of true. bool isAlive = true;
Once declared, you can reference a variable by its name to read or update its value:
score = score + 10; // update Console.WriteLine(score); // read / display
Python
In Python, variables are dynamically typed, meaning you do not need to specify a data type when declaring a variable. The type is inferred from the value assigned.
🤖 Pseudocode
<NAME> = <VALUE>
Examples score = 0 # integer username = "Ze" # string is_alive = True # boolean
Once declared, you can reference a variable by its name to read or update its value:
score += 10 # update print(score) # read / display
JavaScript
In JavaScript, you can declare variables using var, let, or const.
var: Older syntax, function-scoped.let: Modern syntax, block-scoped, used for variables that can change.const: Block-scoped, used for values that won’t change.
🤖 Pseudocode
<KEYWORD> <NAME> = <VALUE>;
Examples let score = 0; // variable that can change const username = "Ze"; // constant variable var isAlive = true; // older syntax
ℹ️ Use let for most variables in modern code and const for values that should remain constant.
Once declared, you can reference a variable by its name to read or update its value:
score += 10; // update console.log(score); // read/display
Related Concepts
- Uses: Data Type
- Uses: Variable
- Mentions: Naming Variables
- Performs: Variable Declaration