forked from gabrielsroka/gabrielsroka.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavaScript-vs-PowerShell.htm
More file actions
214 lines (185 loc) · 3.48 KB
/
Copy pathJavaScript-vs-PowerShell.htm
File metadata and controls
214 lines (185 loc) · 3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<html>
<head>
<title>JavaScript vs. PowerShell</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/default.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/languages/powershell.min.js"></script>
<script>
// see https://highlightjs.org/
hljs.initHighlightingOnLoad();
</script>
</head>
<body>
<table>
<tr>
<th>JavaScript
<th>PowerShell
<tr>
<td>
<pre><code class="javascript">
// This is a single line comment.
/* This is a
comment block.
JS is case-sensitive.
*/
</code></pre>
</td>
<td>
<pre><code class="powershell">
# This is a single line comment.
<# This is a
comment block.
PowerShell is not case-sensitive.
#>
</code></pre>
</td>
<tr>
<td>
<pre><code class="javascript">
// JS variables can start with a letter, $, _
var v = 1;
const c = 2;
let b = 3;
stringDouble = "double quotes";
stringSingle = 'single quotes';
escape = "\"";
template = `a = ${a}`; // ES6 [?]
</code></pre>
</td>
<td>
<pre><code class="powershell">
# 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
$escape = "`""
$template1 = "a = $a" # $a is simple.
$template2 = "a.b = $($a.b)" # $a.b is not simple.
</code></pre>
</td>
<tr>
<td>
<pre><code class="javascript">
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;
</code></pre>
</td>
<td>
<pre><code class="powershell">
$arr = 1, 2
$arr = @()
$arr += 3
$b = $arr[0]
# negative indexes
$arr[0..2] # end is included
$arr.length # or $arr.count
</code></pre>
</td>
<tr>
<td>
<pre><code class="javascript">
hash = {name1: "value", n2: 2};
hash = {};
hash.n3 = 3;
longhash = {
name1: "value",
n2: 2
};
user = {firstName: 'Gabriel', lastName: 'Sroka'};
</code></pre>
</td>
<td>
<pre><code class="powershell">
$hash = @{name1 = "value"; n2 = 2}
$hash = @{}
$hash.n3 = 3
$longhash = @{ # longhash doesn't use semicolons.
name1 = "value"
n2 = 2
}
$user = {firstName = 'Gabriel'; lastName = 'Sroka'}
</code></pre>
</td>
<tr>
<td>
<pre><code class="javascript">
// function name is usually a verb.
function add(a1, a2) {
return a1 + a2;
}
v = add(a1, a2);
</code></pre>
</td>
<td>
<pre><code class="powershell">
# 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
</code></pre>
</td>
<tr>
<td>
<pre><code class="javascript">
if (a == b) /* ... */ // Braces are optional but recommended.
if (a < b)
</code></pre>
</td>
<td>
<pre><code class="powershell">
if ($a -eq $b) { <# ... #> } # Braces are required.
if ($a -lt $b) { <# ... #> }
</code></pre>
</td>
<tr>
<td>
<pre><code class="javascript">
b = true;
if (a == b) {
//
} else if (b < c) {
//
} else {
//
}
while ( ) { }
do { } while ( )
for (i = 0; i < MAX; i++) { }
for (item of collection) // ES6 [?]
</code></pre>
</td>
<td>
<pre><code class="powershell">
$b = $true;
if ($a -eq $b) {
#
} elseif ($b -lt $c) {
#
} else {
#
}
for ($i = 0; $i -lt $MAX; $i++) { }
foreach ($item in $collection)
</code></pre>
</td>
<tr>
<td>
<pre><code class="javascript">
</code></pre>
</td>
<td>
<pre><code class="powershell">
</code></pre>
</td>
</table>
</body>
</html>