what do @private, @public, @class and @param mean in JS

Those are in comments, the JS interpreter won’t even read them. They are comments for the developer and possibly can be used by an auto documentation tool or IDE for syntax help.


These are known as Tags in Javascript. They are used for documentation. You have rightly guessed that they help programmers to understand the code better. Let us take one by one from the above example.

The @private tag marks a symbol as private, or not meant for general use.

So, variable e is supposed to be private and shouldn't be accessed outside the current class.

The @class tag marks a function as being a constructor, meant to be called with the new keyword to return an instance.

So here it says that function Owl is a constructor function and should be called with a new keyword while being invoked.

The @public opposed to @private suggests that the function is publicly available to be accessed outside the current context.

Hence, owl function can be called outside the current class.

The @param describe the parameters of the function. There are three parts of it. First is within {}. It suggests the type of the param. Second is name of the param. Third is after they hyphen(-) sign. It describes the parameter.

So, we have two parameters here. First is of HTMLElement or jQuery type, named element which has description : The element to create the carousel for. Second is of Object type named options with description : The options.

Hope this helps. You can read more about tags here under Block Tags.

Tags:

Javascript