总是有三等号的语言

发布于 2024-12-10 15:03:23 字数 224 浏览 0 评论 0原文

哪些流行的编程语言从一开始就有意设计为同时具有 === 和 ==(并要求程序员弄清楚使用哪一个)。
如今,Javascript、PHP、Ruby(可能还有其他语言)都有一个三等号运算符。但是,尚不清楚这是一个故意的设计决定,还是只是偶然发生(也许是因为该语言以双等号开头,但在某些时候,人们发现双等号并没有完全按照人们希望的方式进行) ).
特别是在 javascript 中,有人记得它第一次出现时是否有三重等于吗?

What popular programming languages were intentionally designed from the beginning to have both === and == (and require the programmer to figure out which one to use).
Javascript, PHP, ruby (and probably others) have a triple equals operator today. But, it is not clear if this was a deliberate design decision, or happened only by accident (perhaps because the language started with double equals, but at some point it was discovered that double equals wasn't quite doing what people wanted it to do).
Specifically in javascript, does anyone remember if it had the triple equals when it first came out?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

拥抱没勇气 2024-12-17 15:03:23

由于我的记忆不太可靠,所以我不能说我记得或者,但由于 ECMA 善意地保留了 ECMA-262 规范的所有修订版,因此可以在“严格等于运算符”时推迟阅读它们被引入到语言中。

我在 ECMA-262 第 1 版,也不是 ECMA-262第二版,但在ECMA-262第三版我们在第 11.9.4 章(第 56 页)中找到了它。由此得出的自然结论是:不,JavaScript 在刚出现时并没有 ===

由于你提到的其他语言没有(据我所知)在任何标准化机构中得到批准,我想如果有语言规范的话,很难找到该语言规范的旧版本。

但值得注意的是,Ruby 中 === 的含义可能与 JavaScript 或 PHP 中的含义有很大不同(它们非常相似)。在 Ruby 中,它通常用于“包含”,即检查某些东西是否存在于其他东西(例如集合)中,而在其他两种语言中,它用于严格的相等检查,这意味着不执行类型转换在应用操作符之前先将其置于操作符的任一侧。

Since my memory isn't very reliable, I can't say that I remember either or, but since ECMA has kindly kept all revisions of the ECMA-262 specification, it's possible to defer from reading them when the "The Strict Equals Operator" was introduced into the language.

I can't find any mention of it in neither ECMA-262 1st Edition, nor ECMA-262 2nd Edition, but in ECMA-262 3rd Edition we find mention of it in chapter 11.9.4 (page 56). The natural conclusion to draw from this is thus: No, JavaScript did not have === when it first came out.

Since the other languages you mention aren't (as far as I know) ratified in any standardisation body, I guess it's harder to find old revisions of the language's specification, if there is any such thing as a specification for the language at all.

It's important to note, however, that the meaning of === in Ruby can be widely different than in JavaScript or PHP (where it is fairly similar). In Ruby, it's usually used for "subsumption", i.e. to check whether something exists within something else (a set, for instance), while in the two other langauges, it's used for strict equality checking, which means no type conversion is performed on either side of the operator before applying it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文