Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Basics of Variables | Getting Started
Introduction to GoLang
course content

Зміст курсу

Introduction to GoLang

Introduction to GoLang

1. Getting Started
2. Data Types
3. Control Structures
4. Functions
5. Arrays and Slices
6. Intro to Structs & Maps

book
Basics of Variables

Variables represent one of the most crucial concepts in any programming language. They essentially serve as named memory locations that allow us to access and modify the data stored at those memory locations.

With variables, we can store various types of data in memory, including numbers and text. We will delve into data types in the next section. For now, let's focus on declaring and initializing variables without specifying their types.

The var keyword is employed to declare a variable, followed by the variable's name (myVar) and an equal sign (=) to assign the value on the right (10) to the variable. Another example for better understanding is:

go

index

copy
1
var myVariable = 7

Another way to achieve the same result is by employing the := operator, and in this scenario, there's no need to utilize the var keyword for variable declaration:

go

index

copy
1
myVariable := 7

Naming Variables

Variables can be given any name, although there are specific rules for declaring variables:

  • A variable's name must start with a letter or an underscore _ character;
  • Variable names are case-sensitive, so myVar and MyVar are distinct variables;
  • A variable cannot have a reserved word as its name. In Go, words like var, for, if, and func, among others, are reserved for special purposes and cannot be used as variable names.

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 4
We're sorry to hear that something went wrong. What happened?
some-alt