gpt4 book ai didi

javascript - 具有不同类型的 Javascript 中的变量赋值的可视化/实用/真实世界示例

转载 作者:行者123 更新时间:2023-11-29 15:10:10 29 4
gpt4 key购买 nike

想要了解变量在 javascript 中如何在分配不同类型的值时工作。

  • 类型 1:字符串 bool 值
  • 类型 2:数组对象函数正则表达式日期

目前引用了两本引起混淆的书。

let mood = "light";
console.log(mood);
// → light
mood = "dark";
console.log(mood);
// → dark

You should imagine bindings as tentacles, rather than boxes. They do not contain values; they grasp them—two bindings can refer to the same value. A program can access only the values that it still has a reference to. When you need to remember something, you grow a tentacle to hold on to it or you reattach one of your existing tentacles to it.

We saw that object values can be modified. The types of values discussed in earlier chapters, such as numbers, strings, and Booleans, are all immutable—it is impossible to change values of those types. You can combine them and derive new values from them, but when you take a specific string value, that value will always remain the same. The text inside it cannot be changed. If you have a string that contains "cat", it is not possible for other code to change a character in your string to make it spell "rat".

来自 Eloquent Javascript


JavaScript lets you give names to values using variables. You can think of a variable as a box that you can fit one thing in. If you put something else in it, the first thing goes away

进一步

Cool! The value of the variable isn’t set in stone, though (they’re called variables because they can vary), and if you want to update it, just use = again:

发件人:Javascript for Kids

不同的作者建议不同的想象力来理解概念。除了盒子,触 Angular 还有什么例子可以帮助我了解上下文。需要了解存储在变量中的内容(值/地址/值的二进制表示)。有没有阐明核心概念的视频、图片资源。

面试官对如何回答这样的问题(字符串类型的变量换其他值)有这样的看法,也可以有自己不同的理解方式

最佳答案

在阅读了互联网上的许多资料后,大多数人将变量视为容器,而不是数据中的变量本身。参见 Storing the information you need — Variables .他们说

We say variables contain values. This is an important distinction to make. Variables aren't the values themselves; they are containers for values. You can think of them being like little cardboard boxes that you can store things in.

还有 W3Schools JavaScript Variables , 他们还说

JavaScript variables are containers for storing data values.

因此,在我的结论中,在具有不同类型的 Javascript 中,最直观/实用/真实世界的变量赋值示例将其想象成一个盒子。

关于javascript - 具有不同类型的 Javascript 中的变量赋值的可视化/实用/真实世界示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55392489/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com