When we make an object like this
function myObject(){
Properties and methods here----
};
We write “function” keyword before name of object is it necessary? All objects are functions in real? Can we not write direct object name like this?
myObject(){
Properties and methods here----
};
No, not all objects are functions. (All functions are objects, though.)
Here, obj
isn't a function:
var obj = {
foo: "bar"
};
Nor dt
here:
var dt = new Date();
The function
keyword is necessary in order to say "what follows is a function declaration or function expression." It's just part of the basic syntax of JavaScript.