Added more information about shorthand variable declaration (#457)

This commit is contained in:
Grejo Joby 2022-12-21 02:23:58 +05:30 committed by GitHub
parent 30a235b655
commit 4944c3bc7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 4 deletions

View File

@ -29,6 +29,7 @@ func main() {
// The `:=` syntax is shorthand for declaring and
// initializing a variable, e.g. for
// `var f string = "apple"` in this case.
// This syntax is only available inside functions.
f := "apple"
fmt.Println(f)
}

View File

@ -1,2 +1,2 @@
736ce4018f275bb8d12e5232349bae93611506b2
iYyAIilyBRf
9aeef52b289d7ad9b9ac79f129d4e49f956c60ef
N5rWndIliJW

5
public/variables generated
View File

@ -43,7 +43,7 @@ calls.</p>
</td>
<td class="code leading">
<a href="https://go.dev/play/p/iYyAIilyBRf"><img title="Run code" src="play.png" class="run" /></a><img title="Copy code" src="clipboard.png" class="copy" />
<a href="https://go.dev/play/p/N5rWndIliJW"><img title="Run code" src="play.png" class="run" /></a><img title="Copy code" src="clipboard.png" class="copy" />
<pre class="chroma"><span class="kn">package</span> <span class="nx">main</span>
</pre>
</td>
@ -133,7 +133,8 @@ zero value for an <code>int</code> is <code>0</code>.</p>
<td class="docs">
<p>The <code>:=</code> syntax is shorthand for declaring and
initializing a variable, e.g. for
<code>var f string = &quot;apple&quot;</code> in this case.</p>
<code>var f string = &quot;apple&quot;</code> in this case.
This syntax is only available inside functions.</p>
</td>
<td class="code">