JavaScript Function Scope

Coding Fluffball
Jun 10, 2021

--

local verses global scope

I like to think of scope as visibility. Where are you able to see 👀 this variable that you have declared. Well, it depends on where you have placed it.

Function Scope local vs global

If the variable is outside of a function it is a global scope. Everyone can see it. If the variable is inside the function is a local scope. Only you can see it.

Local Scope

function local scope

The variable (fluffColor) is inside of the function. When you run console.log(fluffColor) you will get undefined.

Global Scope

function global scope

The variable (fluffColor) is outside of the function. When you run console.log(fluffColor) you will get blue.

blue fluffball

Reference

w3schools

--

--

Coding Fluffball
Coding Fluffball

Written by Coding Fluffball

0 Followers

An average fluffball learning to code :)

No responses yet