/    Sign up×
Community /Pin to ProfileBookmark

JavaScript ~ operator

Hi,
Can someone explain to me what ~ this operator does?

I have found this example on w3school

[code]
~ NOT x = ~ 5 ~0101 1010 10
[/code]

But I don’t really understand it. To me, it seems like it’s used for reversing something but I also had to use this operator for on operation where I wanted to divide a number to the rest.

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@daveyerwinJun 13.2020 — do a search for ...

JavaScript Tilde ~ (Bitwise Not operator)
Copy linkTweet thisAlerts:
@HarshShahJun 22.2020 — Hii RaulRogojan,

The tilde ~ Bitwise NOT operator is commonly used right before an indexOf() to do a boolean check (truthy/falsy) on a string. On its own, indexOf() returns the index number of a String object passed in. So if -1 is returned it will be turned into 0 which is false.

For more please refer to this site...

[https://riptutorial.com/javascript/topic/10643/tilde--](url)
×

Success!

Help @codyhill spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.26,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...