我刚刚在 PHP 中看到了这个语法:
// Fetches the value of $_GET['user'] and returns 'nobody'
// if it does not exist.
$username = $_GET['user'] ?? 'nobody';
Run Code Online (Sandbox Code Playgroud)
为什么我们在 JavaScript 中没有相同的内容?
我厌倦了这样做:
var name = obj['name'] ? obj['name'] : 'GOD';
Run Code Online (Sandbox Code Playgroud)