最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Is there any way to re-assign a const in Chrome DevTools? - Stack Overflow

programmeradmin1浏览0评论

I understand that a const value is not meant to be reassigned, however consider DevTools is meant to tweak around values while debugging, I think there should be a quick way to try out values. Let say in app.js:

const foo = 5;

In the console, I tried re-assigning it in the console foo = 6;

Obviously it does not work (Assignment to constant variable). I have also tried delete(window.foo) but the value still persist even though the delete function returns true.

Currently the workaround is using Local Overrides (and have to setup persistent file system) since live-editing won't work (the value is already there and without Local Overrides, the edited value does not survive a reload).

Is there any easier way to quickly change a const value?

I understand that a const value is not meant to be reassigned, however consider DevTools is meant to tweak around values while debugging, I think there should be a quick way to try out values. Let say in app.js:

const foo = 5;

In the console, I tried re-assigning it in the console foo = 6;

Obviously it does not work (Assignment to constant variable). I have also tried delete(window.foo) but the value still persist even though the delete function returns true.

Currently the workaround is using Local Overrides (and have to setup persistent file system) since live-editing won't work (the value is already there and without Local Overrides, the edited value does not survive a reload).

Is there any easier way to quickly change a const value?

Share Improve this question edited Aug 15, 2019 at 17:50 creativecreatorormaybenot 127k66 gold badges315 silver badges425 bronze badges asked Aug 15, 2019 at 17:40 Luke VoLuke Vo 20.9k25 gold badges127 silver badges230 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7

The solution on Google Chrome DevTools group:

You can actually do that, just not using the console. If you have a breakpoint before the code that uses the value that you want to change, let it hit and then double click on the value of the variable under the Scope drawer and edit it.

const redeclaration in the console was added in Chrome 92 :)

Careful though - this is only supported across separate REPL scripts.

发布评论

评论列表(0)

  1. 暂无评论