Learn Lua in Neovim: Variable Scope — local Keyword, Block Scope & Always Use Local | Episode 14

6views
1likes
0
8:59
T
Taught by Celeste AI - AI Coding Coach
View on YouTube
Description
Know where your variables live — and why it matters. In this episode we compare local and global variables, demonstrate block scoping inside for loops, if blocks, and functions, explore variable shadowing, and make the case for always using local. Every keystroke is shown on screen with 3-second pauses so you can follow along at your own pace. Source code: https://github.com/GoCelesteAI/learn-lua-in-neovim What You'll Learn: - local x = 1 — variable visible only in its block - Global variables (no local) — visible everywhere, dangerous - Block scope — for, if, and function bodies are separate scopes - Shadowing — inner local hides an outer variable of the same name - Why globals cause hard-to-track bugs in larger programs - The rule: always declare variables with local Timestamps: 0:00 Intro 0:12 Preview 0:44 Global vs Local — x = 10 vs local y = 20 1:32 Run: Global and Local output 1:46 Block Scope — if and for 3:53 Run: Block Scope output 4:10 Shadowing — same name, different scopes 6:19 Run: Final output with shadowing 6:36 Code review 6:46 Recap Key Takeaways: 1. local limits a variable to its enclosing block 2. Omitting local creates a global — visible everywhere 3. Blocks (for/if/function) each have their own scope 4. Shadowing: inner local hides outer same-name variable 5. Always use local — globals cause silent, sneaky bugs This is Episode 14 of the Learn Lua in Neovim series. New episodes cover functions as values, closures, tables, and more — all coded inside Neovim. Taught by CelesteAI. Like & subscribe for more tutorials! #lua #neovim #programming #tutorial #beginners #learnlua #luaprogramming #neovimtutorial #luascope #localvsglobal #coding --- Tags: lua, lua tutorial, learn lua, lua scope, lua local, lua global, lua local vs global, lua block scope, lua variable scope, lua shadowing, lua local keyword, lua global variable, lua scope rules, lua for beginners, neovim lua, neovim tutorial, learn lua in neovim, lua episode 14, programming tutorial, coding tutorial, beginner programming, lua 2026, neovim 2026, screenkey, code along, lua basics, lua best practices

Tags

lualua tutoriallearn lualua scopelua locallua globallua local vs globallua block scopelua variable scopelua shadowinglua local keywordlua global variablelua scope ruleslua for beginnersneovim lua
Back to tutorials

Duration

8:59

Published

March 6, 2026

Added to Codegiz

March 15, 2026

Open in YouTube