
Set 1 consists of nine lines of code. Line 1 at indentation level 0: function calculateTotal open parenthesis price comma quantity close parenthesis open curly brace. Line 2, at indentation level 1: StartCommand let EndCommand subtotal equals price asterisk quantity semicolon. Line 3, at indentation level 1: return subtotal plus calculateTax open parenthesis subtotal close parenthesis semicolon. Line 4, at indentation level 1: function calculateTax open parenthesis subtotal close parenthesis open curly brace. Line 5, at indentation level 2: StartCommand let EndCommand taxRate equals 0.05 semicolon. Line 6, at indentation level 2: StartCommand let EndCommand tax equals subtotal asterisk taxRate semicolon. Line 7, at indentation level 2: return tax semicolon. Line 8, at indentation level 1: close curly brace. Line 9 at indentation level 0: close curly brace.
An arrow labeled The Function declaration calculateTax is hoisted to the beginning of its scope points from line 4, 5, 6, 7, 8 to the position below line 1.
Set 2 consists of nine lines of code. Line 1, at indentation level 0: function calculateTotal open parenthesis price comma quantity comma parenthesis open curly brace. Line 2, at indentation level 1: StartCommand let EndCommand subtotal equals price asterisk quantity semicolon. Line 3, at indentation level 1: return subtotal plus calculateTax open parenthesis subtotal close parenthesis semicolon. Note: calculateTax open parenthesis subtotal open parenthesis semicolon is marked Thus, the value of the calculateTax variable here is undefined. Line 4, at indentation level 2: var calculateTax equals function open parenthesis subtotal close parenthesis open curly brace. Note: An arrow labeled the variable declaration is hoisted to the beginning of its scope from the calculateTax in line 4 points to the position below line 1. Line 5, at indentation level 2: StartCommand let EndCommand taxRate equals 0 point 05 semicolon. Line 6, at indentation level 2: StartCommand let EndCommand tax equals subtotal asterisk taxRate semicolon. Line 7, at indentation level 2: return tax semicolon. Note: But the variable assignment is not hoisted. Line 8, at indentation level 1: close curly brace semicolon. Line 9, at indentation level 0: close curly brace.
Back