can anyone tell me actually what it is (var abc={} <==this one is object or?) if that is object what different between var abc=new Object() and var abc={}; Another question is scanner scan =new Scanner(); is same concenpt with var abc= new Object(): ??
Asked
Active
Viewed 150 times
0
-
`this one is object or` empty object, yes - `what different between` nothing significant `is scanner scan =new Scanner()` yes - any early introduction to Javascript would cover all of this (except you don't `scanner scan = new Scanner()` you `var scan = new Scanner()` (or use `let` or `const` in place of `var`) - javascript has little concept of *static types* so you don't declare a variable as a particular type – Jaromanda X May 17 '18 at 02:53
2 Answers
2
Objects can be defined by either of these two methods:
var abc = {};
var abc = new Object();
There is minimal difference between the two, however the first method is preferred by most.
If Scanner
is of type Function then you instantiate it like so:
var scan = new Scanner();
The Scanner function might have been created like this:
function Scanner(total = 5){
this.scans = total;
}
You could use this function like this:
var scan = new Scanner();
console.log(scan); // Output: Object
console.log(scan.scans); // Output: 5
scan = new Scanner(100);
console.log(scan.scans); // Output: 100
scan.scans = 50;
console.log(scan.scans); // Output: 50
var scan2 = { scans: 5 };
console.log(scan2); // Output: Object
console.log(scan2.scans); // Output: 5

Avikar
- 151
- 6
2
For an empty object, both var abc = {} and var abc = new Object() works but there are different approaches with different scenarios/requirements to choose the appropriate style.
You can read more at: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_Objects Go to "Creating new objects"
For var scanner = new Scanner();
Scanner must be a function.

Deependra Rajput
- 42
- 5