Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

dot notation vs bracket notation

/* The dot notation and bracket notation both are used to access the object 
properties in JavaScript. */

/* The main difference between dot notation and bracket notation is that the 
bracket notation allows us to access object properties using variable. */

// Object
let obj = {
	firstName: 'Derrick'
  	lastName: 'Rose'
}

// Dot notation
console.log(obj.firstName)
// Output: Derrick

// Bracket notation
console.log(obj['lastName'])
// Output: Rose
Source by www.tutorialspoint.com #
 
PREVIOUS NEXT
Tagged: #dot #notation #bracket #notation
ADD COMMENT
Topic
Name
6+8 =