O'Reilly logo

Get Programming with Go by Nathan Youngman and Roger Peppé

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Lesson 4. Variable scope

After reading lesson 4, you’ll be able to

  • Know the benefits of variable scope
  • Use a shorter way to declare variables
  • See how variable scoping interacts with for, if, and switch
  • Know when to use a wide or narrow scope

In the course of running a program, many variables are used briefly and then discarded. This is facilitated by the scoping rules of the language.

Consider this

How many things can you keep in your head at once?

It has been suggested that our short-term memory is limited to about seven items, with a seven-digit phone number being an excellent example.

Computers can store many values in their short-term or Random Access Memory (RAM), but remember that code is read not only by computers, but ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required