2
var a = "words";
a instanceOf String;    
#=> false

I can't understand how this code snippet works.

  • Is instanceof a method of a, or of this which locates it in the default scope?
  • If String here is a parameter passed to instanceof, how come it doesn't have parentheses?

2 Answers 2

4

instanceof is an operator, so it's more like + than a function.

See: https://developer.mozilla.org/en/JavaScript/Reference/Operators/instanceof

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

2 Comments

It makes sense, but to be frank, this operator really strange to me
is a is not a a instance of String, what kind of instance it is, and how to use command to check it, something like a.class in Ruby
1

instanceof is an operator like = or %

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.