2020-10-06 23:10:08 +05:30

1.9 KiB

id, challengeType, videoUrl, forumTopicId, title
id challengeType videoUrl forumTopicId title
56533eb9ac21ba0edf2244a8 1 https://scrimba.com/c/cEanysE 18310 使用赋值运算符存储值

Description

在 JavaScript 中,你可以使用赋值运算符将值存储在变量中。 myVariable = 5; 这条语句把Number类型的值5赋给变量myVariable。 赋值过程是从右到左进行的。在将值分配给运算符左侧的变量之前,将解析=运算符右侧的所有内容。
myVar = 5;
myNum = myVar;

数值5被赋给变量myVar中,然后再次将变量myVar解析为5并将其赋给myNum变量。

Instructions

把数值7赋给变量 a。 把变量a中的内容赋给变量b

Tests

tests:
  - text: 不要修改注释上方的代码。
    testString: assert(/var a;/.test(code) && /var b = 2;/.test(code));
  - text: <code>a</code>的值应该是 7。
    testString: assert(typeof a === 'number' && a === 7);
  - text: <code>b</code>的值应该是 7。
    testString: assert(typeof b === 'number' && b === 7);
  - text: 你需要用<code>=</code>把<code>a</code>的值赋给<code>b</code>。
    testString: assert(/b\s*=\s*a\s*;/g.test(code));

Challenge Seed

// Setup
var a;
var b = 2;

// Only change code below this line

Before Test

if (typeof a != 'undefined') {
  a = undefined;
}
if (typeof b != 'undefined') {
  b = undefined;
}

After Test

(function(a,b){return "a = " + a + ", b = " + b;})(a,b);

Solution

var a;
var b = 2;
a = 7;
b = a;