JavaScript PowerShell Python

// This is a single line comment.
/* This is a 
comment block. 

JavaScript is case-sensitive.
*/

# This is a single line comment.
<# This is a 
comment block. 

PowerShell is not case-sensitive.
#>

# This is a single line comment.
"""This is a 
docstring, not a comment.

Python is case-sensitive.
"""

// JavaScript variables can start with a letter, $, _
var v = 1;
const c = 2;
let b = 3;
    
stringDouble = "double quotes";
stringSingle = 'single quotes';
template = `a = ${a}`;

escaped = "\"";

# PowerShell variables start with $
$v = 1
Set-Variable c -option constant -value 2
# n/a [use script:, global:, etc ?]
    
$stringDouble = "double quotes"
$stringSingle = 'single quotes' # no string interpolation
$template1 = "a = $a" # $a is simple.
$template2 = "a.b = $($a.b)" # $a.b is not simple.
$escaped = "`""

# Python variables can start with a letter, _
v = 1
c = 2
b = 3

string_double = "double quotes"
string_single = 'single quotes'
f_string = f'a = {a}'



// an array
arr = [1, 2];
arr = [];
arr.push(3);
b = arr[0];
// no support for negative indexes
arr.slice(0, 3); // end is not included
arr.length;

# an array
$arr = 1, 2
$arr = @()
$arr += 3
$b = $arr[0]
# negative indexes
$arr[0..2] # end is included
$arr.length # or $arr.count

# a list
lst = [1, 2]
lst = []
lst.append(3)
b = lst[0]

lst[0:3] # end is not included
len(lst)

// an object
obj = {name1: "value", n2: 2};
obj = {};
obj.n3 = 3;

longObj = {
    name1: "value",
    n2: 2
};
user = {firstName: 'Gabriel', lastName: 'Sroka'};

# a hashtable
$hash = @{name1 = "value"; n2 = 2}
$hash = @{}
$hash.n3 = 3

$longhash = @{ # longhash doesn't use semicolons.
    name1 = "value"
    n2 = 2
}
$user = @{firstName = 'Gabriel'; lastName = 'Sroka'}

# a dictionary
dct = {'name1': 'value', 'n2': 2}
dct = {}
dct['n3'] = 3

long_dict = {
    'name1': 'value',
    'n2': 2
}
user = {'first_name': 'Gabriel', 'last_name': 'Sroka'}

// function name is usually a verb.
function add(a1, a2) {
    return a1 + a2;
}
 
v = add(a1, a2);

# function name is Verb-Noun. Must be declared before it's called.
function Add-Numbers($a1, $a2) {
    $a1 + $a2 # return is optional.
}
 
$v = Add-Numbers $a1 $a2

# function must be declared before it's called.
def add(a1, a2):
    return a1 + a2


v = add(a1, a2)

if (a == b) /* ... */ // Braces are optional but recommended.
if (a < b) // ...

b = true;
 
if (a == b) {
    //
} else if (b < c) {
    // 
} else {
    //
}
 
while (b) { }
do { } while (b); // note the trailing semicolon
for (var i = 0; i < MAX; i++) { }
for (const item of items) {
    console.log(item);
}

if ($a -eq $b) { <# ... #> } # Braces are required.
if ($a -lt $b) { <# ... #> }

$b = $true
 
if ($a -eq $b) {
    #
} elseif ($b -lt $c) {
    # 
} else {
    #
}

while ($b) { }
do { } while ($b)
for ($i = 0; $i -lt $MAX; $i++) { }
foreach ($item in $items) {
    Write-Host $item
}

if a == b: # ...
if a < b: # ...

b = True

if a == b:
    #
elif b < c:
    #
else:
    #


while b: #
# no do/while loop, use while/break
for i in range(MAX): # ...
for item in items:
    print(item)