diff --git a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp index a1b30c1401..ac999b69f7 100644 --- a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp +++ b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp @@ -1267,11 +1267,13 @@ static Bytecode::CodeGenerationErrorOr assign_accumulator_to_variable_decl Bytecode::CodeGenerationErrorOr VariableDeclaration::generate_bytecode(Bytecode::Generator& generator) const { for (auto& declarator : m_declarations) { - if (declarator->init()) + if (declarator->init()) { TRY(declarator->init()->generate_bytecode(generator)); - else + TRY(assign_accumulator_to_variable_declarator(generator, declarator, *this)); + } else if (m_declaration_kind != DeclarationKind::Var) { generator.emit(js_undefined()); - TRY(assign_accumulator_to_variable_declarator(generator, declarator, *this)); + TRY(assign_accumulator_to_variable_declarator(generator, declarator, *this)); + } } return {};