dongmu2174 2018-12-10 14:48 采纳率: 100%
浏览 22
已采纳

Javascript的布尔翻译到Golang

In JavaScript I see functions like:

function SomeFunc(i) {
    var f = 0x80000000;

    return Boolean(i & f);
}

What would be an analog in Golang? First of all, I see 0x80000000 is not possible, syntax is the second question

  • 写回答

2条回答 默认 最新

  • dtvq4978 2018-12-10 14:49
    关注

    In JavaScript, coercing any non-boolean value to boolean just does a "falsiness" check; for the most part, any non-empty value is false and everything else is true. So the Go equivalent for an integer value would simply be:

    return i != 0
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?