2

I came across the following code snippet and am confused about what the not: is doing. Is it a tag? If so, are there any other uses for it?

var foo = {
   not: function(bool) { return !bool; }
}

Can you provide me with a possible use scenario for this kind of syntax?

2 Answers 2

6

This is not a tag.

It is declaring an object with a property called "not" which is a function.

You can find more details at JSON and Javascript syntax

Sign up to request clarification or add additional context in comments.

2 Comments

How dumb I am. still struggling to wind my head around for javascript syntax. Thanks a lot!!
It isn't JSON. JSON is a data format based on a subset of JS that this doesn't conform to.
6

In Javascript the syntax { property: value } creates an object with the property property, whose value is value. So your code defined an object which has the property not, whose value is a function which returns the negation of its argument.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.