The error indicates that msSpeechRecognition is being accessed from the window object as window.msSpeechRecognition. You can only add something to globalThis by declaring it with var. If you want to use const instead, you will need to replace references to window.msSpeechRecognition with just msSpeechRecognition.

Answer from Ryan Pattillo on Stack Overflow
๐ŸŒ
Medium
medium.com โ€บ @robinviktorsson โ€บ understanding-the-differences-between-var-let-and-const-in-javascript-and-typescript-0ddd90c0b672
Understanding the Differences Between var, let, and const in JavaScript and TypeScript ๐Ÿ’ป | by Robin Viktorsson | Medium
March 10, 2025 - It's ideal for constants, objects, or arrays where you don't want to change the reference, but you may need to modify the object itself. In modern JavaScript/TypeScript, avoid using var unless absolutely necessary.
Discussions

var, const, let
Rule of thumb: start with const, if you need to change the value later, change to let, and forget about var. More on reddit.com
๐ŸŒ r/typescript
23
9
April 24, 2018
Difference between var, let and const
Using the function keyword creates a function declaration. Function declarations are hoisted to the top of the scope, thus the following code works fine: add(1, 2) function add (a, b) { return a + b } There are readability advantages to using the function keyword as it clearly communicates that this is a function. We can also create an anonymous function expression and, because functions in JavaScript are first class citizens, assign a function to a named variable with let, const or var. Keep in mind though, variables declared with let and const are hoisted, but not initialized with a value. Whereas variables declared with var are hoisted and initialized with the value undefined. So because add is invoked prior to it's initialization in the code below we encounter an error. With let/const: add(1, 2) // Reference error - cannot access 'add' before initialization const add = function (a, b) { return a + b } With var: add(1, 2) // Type error - 'add' is not a function (as it is initialized as undefined when hoisted) var add = function (a, b) { return a + b } If you're assigning a function to a variable I can't think of any situation where you wouldn't use const. Functions should always be pure and immutable whenever possible. Given a certain input, the output should always be consistently the same. Using const protects you from accidentally reassigning a variable containing a function expression. Compare this to use of the function keyword, which allows you to declare a named function twice, overiding the previous: function add (a, b) { return a + b } function add (a, b) { return a - b } add(2, 1) // 1 This is a disadvantage of function declarations versus expressions. Provided you understand the pros/cons and how hoisting works, it is really personal choice whether you prefer function declarations versus expressions. More on reddit.com
๐ŸŒ r/learnjavascript
31
58
March 28, 2022
๐ŸŒ
Tutorial Teacher
tutorialsteacher.com โ€บ typescript โ€บ typescript-variable
TypeScript Variable Declarations: var, let, const
Variables can be declared using const similar to var or let declarations. The const makes a variable a constant where its value cannot be changed.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ javascript โ€บ difference-between-var-let-and-const-keywords-in-javascript
Difference between var, let and const keywords in JavaScript - GeeksforGeeks
This happens because let variables are hoisted but not initialized, so they remain in the TDZ until the declaration is executed. ... Hoisting with const: The variable x is declared with const, which is block-scoped and not hoisted.
Published ย  January 16, 2026
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ var-let-and-const-whats-the-difference
Var, Let, and Const โ€“ What's the Difference?
April 2, 2020 - Just like let, const declarations are hoisted to the top but are not initialized. So just in case you missed the differences, here they are: var declarations are globally scoped or function scoped while let and const are block scoped.
๐ŸŒ
DEV Community
dev.to โ€บ steckdev โ€บ exploration-of-var-vs-const-in-nodejs-application-j20
Exploration of var vs const in NodeJS Application - DEV Community
March 1, 2023 - When a variable is declared with const, the compiler can determine that it will never change, and can optimize the code accordingly. ... In this code, myNumber is declared with let, which means that it can be re-assigned.
Find elsewhere
๐ŸŒ
Tektutorialshub
tektutorialshub.com โ€บ home โ€บ typescript โ€บ typescript let vs var vs const
Typescript Let vs Var vs Const - Tektutorialshub
March 15, 2023 - There are four ways you can declare a variable. They are ... Use var and let to define any variable, with or without type or initial value. We use the const keyword initialize a constant whose value does not change.
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ differences-between-var-let-const-javascript
var, let, and const in JavaScript โ€“ the Differences Between These Keywords Explained
January 11, 2023 - Therefore, it can be accessed outside the block. Because anotherLargeNumber has a block scope, accessing it outside the block throws an anotherLargerNumber is not defined. In this regard, const is different from var and let.
๐ŸŒ
Gazar
gazar.dev โ€บ typescript โ€บ when-to-use-let-vs-const
When to Use let vs const in TypeScript | Gazar
const PI = 3.14; PI = 3.14159; ... your intent and reduce the cognitive load on readers of your code." In TypeScript, the choice between let and const boils down to intent and necessity....
๐ŸŒ
DEV Community
dev.to โ€บ hexnickk โ€บ js-interview-in-2-minutes-var-let-const-39p1
JS interview in 2 minutes / var โš”๏ธ let โš”๏ธ const - DEV Community
February 15, 2022 - Quick answer: These are a few ways to declare variables. var is a legacy one, let and const are new ones, where let is for mutable variable reference and const is for immutable reference.
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ javascript โ€บ difference between var, let, and const in javascript
Difference Between Var, Let, and Const in Javascript | Scaler Topics
June 21, 2024 - Var is function-scoped and can be both re-declared and updated, making it the more flexible, yet potentially riskier option from older JavaScript standards. In contrast, Let, introduced in ES6, is block-scoped and can only be updated, not ...
๐ŸŒ
Upmostly
upmostly.com โ€บ home โ€บ typescript โ€บ exploring the differences between var, let, and const
TypeScript Demystified: Exploring the Differences between var, let, and const - Upmostly
March 28, 2023 - const var1 = 'foo'; //type is 'foo' let var2 = 'bar'; // type is string ยท Here, since TypeScript trusts that the variable wonโ€™t change type, it will give the variable the type of โ€˜fooโ€™, instead of string.
๐ŸŒ
TecAdmin
tecadmin.net โ€บ what-is-var-let-and-const-in-javascript
Understand `var`, `let` and `const` Variables in JavaScript
April 26, 2025 - Attempting to reassign person itself (like person = { name: "Doe" }) will result in a TypeError since const doesn't allow reassigning the entire variable.
๐ŸŒ
DEV Community
dev.to โ€บ skinnypetethegiraffe โ€บ function-or-const-which-do-you-prefer-typescriptjavascript-apa
function or const, which do you prefer? (TypeScript/ ...
April 15, 2022 - Personally, after years of using const, I have recently switched back over to function for a few reasons. The intent is clear and concise, so that readers quickly differentiate between variables and functions.
๐ŸŒ
Stack Abuse
stackabuse.com โ€บ the-difference-between-var-let-and-const-in-javascript-and-best-practices
The Difference Between var, let and const in JavaScript and Best Practices
May 22, 2023 - Avoid using var. let is preferred to const when it's known that the value it points to will change over time.
๐ŸŒ
Cloudhadoop
cloudhadoop.com โ€บ home
Typescript let, var, Const keyword with examples | Javascript | ES6
March 6, 2024 - Attempting to redeclare the same ... variable value. ... const is similar to let, but variables declared with const must be initialized immediately and cannot be reassigned:...