Skip to content

Commit

Permalink
Update variables-and-constants.md
Browse files Browse the repository at this point in the history
Add a link back to type assertion in the type conversion notes.
  • Loading branch information
psx95 authored Jun 3, 2024
1 parent aa265cf commit 85cd200
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion variables-and-simple-data-types/variables-and-constants.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ a, b := 10, 5 // Go allows multiple variables to be initialized all at


#### Type conversion
Go **does not support implicit conversions between data types***. If a type conversion is required, it has to be explicit. So for instance,
Go **does not support implicit conversions between data types**. If a type conversion is required, it has to be explicit. So for instance,

```go
var i int = 5 // declare and initialize
Expand All @@ -36,6 +36,9 @@ f = i // ERROR - implicit conversion not allowed in Go and will result
f = float32(i) // Have to be explicit with the intent to convert to a different type.
```

##### Related Note
Go allows you to *unpack* the concrete type from an interface type via [type-assertions](../object-orientation-polymorphism/interfaces.md#type-assertions---get-concrete-type-from-interface-type). This is not exactly a type coversion, but can come handy when dealing with interfaces and their subtypes.

### Constants in Go
Constants in Go are declared using the `const` keyword. Constants cannot change values once they are initialized and the value of the constant has to be determinable at compile time. Unlike variables constants do not need to be declared locally and so we can have unused constants in a Go program without any compile-time errors.

Expand Down

0 comments on commit 85cd200

Please sign in to comment.