Skip to content

Files

Latest commit

 

History

History
38 lines (25 loc) · 753 Bytes

UseDeclaredVarsMoreThanAssignments.md

File metadata and controls

38 lines (25 loc) · 753 Bytes

Pattern: Unused variable

Issue: -

Description

Generally variables that are not used more than their assignments are considered wasteful and not needed.

How

Remove the variables that are declared but not used.

Example of incorrect code:

function Test
{
    $declaredVar = "Declared and used"
    $declaredVar2 = "Not used"
    Write-Output $declaredVar
}

Example of correct code:

function Test
{
    $declaredVar = "Declared and used"
    Write-Output $declaredVar
}

Further Reading