More actions
Updated via bot |
m Updated via bot |
||
| Line 1: | Line 1: | ||
<span id=" | <span id="variable_declarationdeclare-a-variable"></span> | ||
<span id="c"></span> | |||
== C# == | |||
In [[C_Sharp|C#]], a variable declaration follows this format: | |||
<sub>🤖 ''Pseudocode''</sub> | <sub>🤖 ''Pseudocode''</sub> | ||
<syntaxhighlight lang="console"><DATA_TYPE> <NAME> = <VALUE>;</syntaxhighlight> | <syntaxhighlight lang="console"><DATA_TYPE> <NAME> = <VALUE>;</syntaxhighlight> | ||
# <code><DATA_TYPE></code>: | # <code><DATA_TYPE></code>: The [[Data_Type|type]] of value the [[Variable|variable]] will hold (e.g., number, text, [[Boolean|boolean]]). | ||
# <code><NAME></code>: | # <code><NAME></code>: A recognizable name for the variable. | ||
# <code><VALUE></code>: | # <code><VALUE></code>: The initial value to store (optional; a variable can also be declared without an initial value). | ||
<syntaxhighlight lang="csharp">// An integer variable named score with the initial value of 0. | <syntaxhighlight lang="csharp">// An integer variable named score with the initial value of 0. | ||
| Line 23: | Line 21: | ||
// A boolean variable named named isAlive with the initial value of true. | // A boolean variable named named isAlive with the initial value of true. | ||
bool isAlive = true;</syntaxhighlight> | bool isAlive = true;</syntaxhighlight> | ||
----- | |||
Once declared, you can reference a variable by its name to read or update its value: | |||
<syntaxhighlight lang="csharp">score = score + 10; // update | |||
Console.WriteLine(score); // read / display</syntaxhighlight> | |||
<span id="python"></span> | |||
== 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. | |||
<sub>🤖 Pseudocode</sub> | |||
<syntaxhighlight lang="console"><NAME> = <VALUE></syntaxhighlight> | |||
<syntaxhighlight lang="python">Examples | |||
score = 0 # integer | |||
username = "Ze" # string | |||
is_alive = True # boolean</syntaxhighlight> | |||
----- | |||
Once declared, you can reference a variable by its name to read or update its value: | |||
<syntaxhighlight lang="python">score += 10 # update | |||
print(score) # read / display</syntaxhighlight> | |||
<span id="javascript"></span> | |||
== JavaScript == | |||
In JavaScript, you can declare variables using <code>var</code>, <code>let</code>, or <code>const</code>. | |||
* <code>var</code>: Older syntax, [[Function|function]]-scoped. | |||
* <code>let</code>: Modern syntax, block-scoped, used for variables that can change. | |||
* <code>const</code>: Block-scoped, used for values that won’t change. | |||
<sub>🤖 Pseudocode</sub> | |||
<syntaxhighlight lang="console"><KEYWORD> <NAME> = <VALUE>;</syntaxhighlight> | |||
<syntaxhighlight lang="javascript">Examples | |||
let score = 0; // variable that can change | |||
const username = "Ze"; // constant variable | |||
var isAlive = true; // older syntax</syntaxhighlight> | |||
<blockquote>ℹ️ Use let for most variables in modern code and const for values that should remain constant. | |||
</blockquote> | |||
----- | |||
Once declared, you can reference a variable by its name to read or update its value: | |||
<syntaxhighlight lang="javascript">score += 10; // update | |||
console.log(score); // read/display</syntaxhighlight> | |||
<span id="related-concepts"></span> | <span id="related-concepts"></span> | ||
== Related Concepts == | == Related Concepts == | ||
| Line 31: | Line 78: | ||
* ''Uses'': [[Variable|Variable]] | * ''Uses'': [[Variable|Variable]] | ||
* ''Mentions'': [[Naming_Variables|Naming Variables]] | * ''Mentions'': [[Naming_Variables|Naming Variables]] | ||
* ''Performs'': [[Variable_Declaration|Variable Declaration]] | |||
Latest revision as of 17:25, 23 October 2025
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