On Hoisting In Javascript Python Powershell

Pavol Kutaj
2 min readOct 6, 2021

--

The aim of this page📝 is to describe hoisting as a mechanism in 3 interpreted, dynamically typed languages: JS, PowerShell, and Python.

  • Tried to put a helper _function to the bottom of the PowerShell functionso that it gets out of the way for readability purposes and this is not working → I knew that JavaScript would handle that OK.
LANG       | SUPPORT
-----------|--------
JS | YES
PowerShell | NO
Python | NO
hoist
To raise; to lift; to elevate (especially, to raise or lift to a desired elevation, by means of tackle or pulley, said of a sail, a flag, a heavy package or weight).

1. javascript

JavaScript Hoisting refers to the process whereby the interpreter allocates memory for variable and function declarations prior to execution of the code.

— from https://developer.mozilla.org/en-US/docs/Glossary/Hoisting

/* hoisting.js */

catName("Chloe");

function catName(name) {
console.log("My cat's name is " + name);
}

>>> "My cat's name is Chloe"

2. python

  • there is no-hoisting-at-all in python
# hoisting.py

catName("Chloe")


def catName(name):
print(f"My cat's name is {name}")

# >>> NameError: name 'catName' is not defined

3. powershell

  • but no hoisting in PowerShell
# hoisting.ps1
catName "Chloe"

function catName($name) {
Write-Host "My cat's name is $name"
}

# >>> catName : The term 'catName' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

4. links

--

--

No responses yet