7

🐒: if (a == 2) return true else return false

 1 year ago
source link: https://www.v2ex.com/t/949367
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

V2EX  ›  程序员

🐒: if (a == 2) return true else return false

  idealhs · 7 小时 45 分钟前 · 1683 次点击

🤡: return a == 2 ? true : false;

return a == 2 😅:???

茴茴茴茴茴茴茴茴茴茴茴茴茴茴茴茴茴茴茴茴茴茴茴

27 条回复    2023-06-17 00:35:56 +08:00
cczhrd

cczhrd      7 小时 37 分钟前   ❤️ 1

while(a==2) return true return false
wu67

wu67      7 小时 34 分钟前

准确的说, 局限于 js 场景, 应该是 return a === 2, 其他有强类型的才是==
sechi

sechi      7 小时 33 分钟前

if (a === true)
return true
else
return false
idealhs

idealhs      7 小时 32 分钟前

@cczhrd 👍
idealhs

idealhs      7 小时 30 分钟前

@wu67 👍向前端工程师学习!
cczhrd

cczhrd      7 小时 30 分钟前

return a-1==1
return a-2==0
....
....
idealhs

idealhs      7 小时 29 分钟前

@cczhrd #6 👍👍👍果然抛砖引玉,大家尽情发挥!
cczhrd

cczhrd      7 小时 29 分钟前

for(;;) return a==2
taotaodaddy

taotaodaddy      7 小时 12 分钟前

> "4" + "2" - "2" === 40
true
ccyu220

ccyu220      6 小时 47 分钟前

return !isNaN(number) && Number(number) === 2
JinshengChen

JinshengChen      6 小时 42 分钟前

???想表达啥
DOLLOR

DOLLOR      6 小时 40 分钟前

a == 2
a === 2
a is 2
Object.is(a, 2)
a.equals(2)
!(a - 2)
!(a^2)
kera0a

kera0a      6 小时 36 分钟前 via iPhone

他那个例子不好直接 return ,需要对全局变量赋值
应该是页面上的元素绑定了
zhujiaofan

zhujiaofan      6 小时 30 分钟前

if (!true)
return true ? false : true
else
return false ? true : false
bv

bv      6 小时 25 分钟前

if (a == 2 == true) return true else return false
chendy

chendy      6 小时 24 分钟前

只能说有时候脑抽了会这么写
但是 ide 有警告,直接自动修复就完事了
mxT52CRuqR6o5

mxT52CRuqR6o5      6 小时 16 分钟前   ❤️ 4

不是还有个著名的笑话:如果我和老婆意见一致,那就听我的;如果意见不一致,那就听老婆的
return a==b?a:b
lovelylain

lovelylain      6 小时 13 分钟前 via Android

if (a==1 && b==2) || (a!=1 && b!=2) {
}
sillydaddy

sillydaddy      3 小时 28 分钟前

@mxT52CRuqR6o5 #17
你这个可以放到程序员的冷笑话集锦里,😂太逗了,还有没有类似的。
EscYezi

EscYezi      3 小时 20 分钟前 via Android

return Optional.ofNullable(a)
.map(Objects::toString)
.map(BigDecimal::new)
.map(d->d.compareTo(new BigDecimal (2))==0)
.orElse(false);
😜
beijinglowb

beijinglowb      3 小时 12 分钟前

@EscYezi rxjs 是这样的
cyrbuzz

cyrbuzz      2 小时 58 分钟前

!!!(2^a)
rabbbit

rabbbit      1 小时 35 分钟前   ❤️ 1

🐶
interface Is2Interface {
is2(a: number): boolean;
}

abstract class AbstractIs2 implements Is2Interface {
is2(a: number): boolean {
return a === 2;
}
}

class Is2 extends AbstractIs2 {
is2(a: number): boolean {
if (a === 2) {
return true
} else {
return false
}
}
}

interface Is2FactoryInterface {
getIs2(): AbstractIs2;
}

abstract class AbstractIs2Factory implements Is2FactoryInterface {
getIs2(): AbstractIs2 {
return new Is2();
};
}

class Is2Factory extends AbstractIs2Factory {
private is2: AbstractIs2 = new Is2();
getIs2(): AbstractIs2 {
return this.is2;
};
}

class Main {
public static main(): void {
const is2Factory = new Is2Factory();
const is2 = is2Factory.getIs2();
const a = 2;
console.log(is2.is2(a));
}
}

Main.main();
proxychains

proxychains      1 小时 29 分钟前 via Android

@rabbbit 这是更是重量级
ochatokori

ochatokori      1 小时 10 分钟前 via Android

return a !== 2 ? false : true
fzls

fzls      1 小时 1 分钟前

@rabbbit 设计模式大师啊

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK