Requirement of parenthesis after operator

Hello, I had a question about writing javascript code. When using dot operators, we sometimes add () after the operator, and sometimes don’t. For example, the following does not require ():


While the following does:


How do we know which operators require it?

Hello! This is actually to do with what toUpperCase() and length are. In JavaScript, all values are instances of objects (which are like blueprints-you’ll learn more about JS objects later in the course). All objects have built in methods (or functions) that can do certain things to an instance of the object (such as the string object’s .toUpperCase() method)-all methods need parentheses after them (and some take arguments). Objects also have properties, which contain information about each instance. For example, each string instance has a length property that stores that string’s length. Since properties are just like variables, you don’t need the parentheses when using them.

If you’re interested in learning more about JS objects, this is quite a good place to start.

I hope that helps!