How to declare a constant array in JavaScript?
- const arr = [];
- const arr = new Array();
- const arr = {}
- const arr = [1, 2, 3];
To declare a constant array in JavaScript, you can use the const keyword followed by square brackets, like const arr = [];. The const keyword ensures that the variable arr cannot be reassigned, making it a constant array.
Loading...
Related Quiz
- You've encountered a bug in your JavaScript code where a variable is not retaining an expected value within a nested function. What feature of JavaScript should you explore to troubleshoot this issue?
- In JavaScript, the Symbol data type can be used to create _________.
- In a UI with nested dropdown menus, a developer wants to ensure that clicking a nested menu item does not trigger the click event of its parent menu. What method can be used to stop the event from reaching the parent menu?
- While working with React, you notice a function defined using the function keyword is not updating the component state as it should. You suspect it's related to the "this" keyword. What might be the problem?
- Which keyword is used to check a condition in JavaScript?