freeCodeCamp/curriculum/challenges/chinese/02-javascript-algorithms-an.../basic-javascript/storing-values-with-the-ass...

1.3 KiB
Raw Blame History

id title challengeType videoUrl forumTopicId dashedName
56533eb9ac21ba0edf2244a8 使用赋值运算符存储值 1 https://scrimba.com/c/cEanysE 18310 storing-values-with-the-assignment-operator

--description--

在 JavaScript 中,你可以使用赋值(assignment)运算符 =)将值存储在变量中。

myVariable = 5;

这条语句把 Number 类型的值 5 赋给变量 myVariable

在将值分配给运算符左侧的变量之前,将解析 = 运算符右侧的所有内容。

var myVar;
myVar = 5;

首先,此代码创建一个名为 myVar 的变量。 数值 5 被赋给变量 myVar。 现在,如果 myVar 再次出现在代码中,程序将会将它视为 5

--instructions--

把数值 7 赋给变量 a

--hints--

你不应该修改注释上面的代码。

assert(/var a;/.test(code));

a 的值应该为 7。

assert(typeof a === 'number' && a === 7);

--seed--

--before-user-code--

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

--after-user-code--

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

--seed-contents--

// Setup
var a;

// Only change code below this line

--solutions--

var a;
a = 7;