| 152 | // console.log(test1);//undefined |
| 153 | |
| 154 | function testingVar() { |
| 155 | // * hosting var |
| 156 | // ! no error |
| 157 | // console.log(test1);// undefined |
| 158 | var test = 1; |
| 159 | |
| 160 | // * var can be reassigned |
| 161 | test = 2; |
| 162 | console.log(test); // 2 |
| 163 | |
| 164 | // * var can re declared |
| 165 | var test = 3; |
| 166 | console.log(test); // 3 |
| 167 | |
| 168 | // ! since var is function scope |
| 169 | // * we can access var declared variables from an outer scope |
| 170 | if (true) { |
| 171 | var access = true; |
| 172 | } |
| 173 | |
| 174 | // * var is function scoped |
| 175 | console.log(access); // true |
| 176 | } |
| 177 | |
| 178 | testingVar(); |
| 179 | |