草庐IT

string-math

全部标签

javascript - 为什么 :Math. floor(2e+21) != ~~(2e+21)

我不是按位运算符的专家,但我经常在比赛中看到程序员使用256k演示的模式。不是使用Math.floor()函数,而是使用双按位NOT运算符~~(可能更快?)。像这样:Math.floor(2.1);//2~~2.1//2搜索发现还有更多使用相同方式的模式:2.1|0//22.1>>0//2在开发控制台中玩这个时,我注意到一个我不确定我是否完全理解的行为。Math.floor(2e+21);//2e+21~~2e+21;//-11198791682e+21|0;//-1119879168引擎盖下发生了什么? 最佳答案 正如FelixK

Javascript 权威指南 : the confusion of steps of converting object to a string

根据Javascript权威指南第6版3.8.3节:Toconvertanobjecttoastring,JavaScripttakesthesesteps:•IftheobjecthasatoString()method,JavaScriptcallsit.Ifitreturnsaprimitivevalue,JavaScriptconvertsthatvaluetoastring(ifitisnotalreadyastring)andreturnstheresultofthatconversion.Notethatprimitive-to-stringconversionsarea

javascript - Javascript Math.Round 与 C# Math.Round 有多接近?

我从阅读中知道thisStackoverflowquestion编译器将查看您的数字,确定中点是偶数还是奇数,然后返回偶数。示例数字是2.5,四舍五入为3。我尝试了自己的小实验以查看会发生什么,但我还没有找到任何关于此的规范,或者即使它在浏览器之间是一致的。这是一个使用jQuery进行显示的JavaScript片段示例:$(document).ready(function(){$("#answer").html(showRounding());});functionshowRounding(){varanswer=Math.round(2.5);returnanswer;}这将返回“3

javascript - 为什么 Math.pow(1, Infinity) 返回 NaN?

我一直认为1的任何次方都等于1,但是Math.pow(1,Infinity)返回NaN。为什么不是1? 最佳答案 这更像是一个数学问题而不是Javascript问题,因此您使用数学解释,例如以下(http://mathforum.org/library/drmath/view/53372.html):Whenyouhavesomethinglike"infinity,"youhavetorealizethatit'snotanumber.Usuallywhatyoumeanissomekindoflimitingprocess.So

javascript - 为什么不推荐使用 String.prototype.substr()?

ECMAScript标准中提到了它here那:...ThesefeaturesarenotconsideredpartofthecoreECMAScriptlanguage.ProgrammersshouldnotuseorassumetheexistenceofthesefeaturesandbehaviourswhenwritingnewECMAScriptcode.ECMAScriptimplementationsarediscouragedfromimplementingthesefeaturesunlesstheimplementationispartofawebbrowse

javascript - 这个新语法 gql`string` 是什么

这个问题在这里已经有了答案:Backticks(`…`)callingafunctioninJavaScript(3个答案)关闭2年前。constGET_DOGS=gql`{dogs{idbreed}}`;我从here中找到了这个新语法.你能解释一下这个语法吗?我在哪里可以找到有关它的详细信息?

javascript - 创建小书签 : Append current URL with specific string

我正在尝试创建一个小书签,它将更改我当前所在页面的URL,并加载一个更改了URL字符串的新页面。我已经查看了许多关于小书签的其他主题,但我还没有找到适合我的解决方案。我希望能够更改如下所示的URL:http://mywebsite.com/directory/page.html?referral=Google&visit=1到:http://mywebsite.com/directory/page.html?dog=Fido&cat=Mittens三个目标:1)在?之后删除现有URL中的任何内容标记。2)在问号后附加“dog=Charlie&cat=Mittens”。3)立即使用新UR

javascript - "String"对象和 JavaScript 中的字符串文字的区别

这个问题在这里已经有了答案:关闭11年前。PossibleDuplicate:DifferencebetweenthejavascriptStringTypeandStringObject?在Firebug中编写这段简单的代码:console.log(newString("stringinstance"));console.log("stringinstance");你看到的是:为什么这两个console.log()调用会导致不同的输出?为什么字符串文字与通过String对象创建字符串不同?它是Firebug表示样式吗?或者它们在性质上有什么不同?

javascript - 未捕获的断言错误 : path must be a string error in Require. js

我在使用node-webkit的简单示例中遇到以下错误:UncaughtAssertionError:pathmustbeastring索引.html//base.jsrequire(["test"],function(test){test.init();});//test.jsdefine(function(){window.c=window.console;return{init:function(){c.log('test.init');},destroy:function(){c.log('test.destroy');}}}); 最佳答案

javascript - 为什么 Math.max(...[]) 在 ES2015 中等于 -Infinity?

Math.max([])将是0而[..[]]是[]但为什么Math.max(...[])在ES2015中等于-Infinity? 最佳答案 Math.max([])发生的事情是[]首先转换为字符串,然后转换为数字。它实际上不被视为参数数组。使用Math.max(...[])时,数组被视为通过展开运算符的参数集合。由于数组为空,这与不带参数调用相同。哪个根据docs产生-InfinityIfnoargumentsaregiven,theresultis-Infinity.一些示例显示调用数组的区别:console.log(+[]);/