feat: {}{} is undefined example

adding ```{}{}``` is undefined section
This commit is contained in:
Denys Dovhan
2021-02-03 19:00:53 +02:00
committed by GitHub

View File

@@ -103,6 +103,7 @@ Currently, there are these translations of **wtfjs**:
- [Same variable redeclaration](#same-variable-redeclaration)
- [Default behavior Array.prototype.sort()](#default-behavior-arrayprototypesort)
- [resolve() won't return Promise instance](#resolve-wont-return-promise-instance)
- [```{}{}``` is undefined](#user-content--is-undefined)
- [📚 Other resources](#-other-resources)
- [🎓 License](#-license)
@@ -1733,9 +1734,40 @@ thePromise.then(value => {
> This function flattens nested layers of promise-like objects (e.g. a promise that resolves to a promise that resolves to something) into a single layer.
– [Promise.resolve() on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/resolve)
- [Promise.resolve() on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/resolve)
The specification is [ECMAScript 25.6.1.3.2 Promise Resolve Functions](https://tc39.es/ecma262/#sec-promise-resolve-functions). But it is not quite human-friendly.
## `{}{}` is undefined
Write them in console. They will return the value that defined in last object.
```
{}{}; // undefined
{}{}{}; // undefined
{}{}{}{}; // undefined
{foo: 'bar'}{}; // 'bar'
{}{foo: 'bar'}; // 'bar'
{}{foo: 'bar'}{}; // 'bar'
{a: 'b'}{c:' d'}{}; // 'd'
{a: 'b', c: 'd'}{}; // SyntaxError: Unexpected token ':'
({}{}); // SyntaxError: Unexpected token '{'
```
### 💡 Explanation:
When inspecting each ```{}```, they returns undefined. If you inspect ```{foo: 'bar'}{}```, you will find ```{foo: 'bar'}``` is ```'bar'```.
There are 2 meaning for {}: object and block.
For example, the {} in ()=>{} means block. So we need to use ()=>({}) to return an object.
Let's use ```{foo: 'bar'}``` as a block. Write this snippet in your console:
```
if(true) {foo: 'bar'} // 'bar'
```
Surprisingly, it behaviors the same! You can guess here that ```{foo: 'bar'}{}``` is a block.
# 📚 Other resources