While loops in js have block-level scope

does the while loop have no block-level scope like the for loop

if I define a human variable in the while loop, will the variable be cleared before I continue to operate in the previously defined variable in the next loop

Dec.14,2021

1. We can think that expressions with {} are block-level scope, provided that with let const, variables defined by var do not have block-level scope.
2. Let's take a look at the comparison: var is used in
while to declare variables
:

clipboard.png

a


let:

clipboard.png

We found that using the let declaration, the value printed for the first time is undefined, indicating that the value of b in each loop is a new value ( block-level scope takes effect ), and an error is reported when printing the value of b outside the loop, indicating that the variable b is not available outside {}. indicates that the block-level scope takes effect again.

if you have any questions, please leave a message.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3554b-2b4d1.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3554b-2b4d1.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?