Introduction
JavaScript is a language of the Web. This series of articles will talk about my observations learned during my decade of software development experience with JavaScript and what mistakes generally developers make and what differences they should be aware of.
Data types
Q: How many data types are there in JS?
Primitive data type
- String
- Number
- Boolean
- Undefined
- Null
Non-primitive (reference) data type
- Object
- Array
- RegExp
Q: How do you specify the data types in JS?
- var x=10; // holds number
- var x=”javascript”; // holds string
Example
- // define an object
- var object = {
- 'boolean': true,
- 'number': 1,
- 'string': 'a',
- 'array': [1, 2, 3]
- };
- // determine the size of the object
- var size = sizeof(object);
- //output: size is 92 bytes
Q: What is the difference between Undefined and Null?
Ans: In JavaScript, undefined means a variable has been declared but has not yet been assigned a value, such a,
- var TestVar;
- alert(TestVar); //shows undefined
- alert(typeof TestVar); //shows undefined
- null is an assignment value.It can be assigned to a variable as no value: var TestVar = null;
- alert(TestVar); //shows null
- alert(typeof TestVar); //shows object
Objects
Objects are variables too. However, objects can contain many values.
Ex
- var person = {age:59, address:"Delhi”};
Q: Do you know a simple way to create objects?
- var obj = {};
- //undefined
- typeof(obj);
- "object"
- Object Properties
- You can access object properties in two ways: objectName.propertyName
- or
- objectName["propertyName"]
Ex
- person.age
- Or
- Person[“age”]
Object Methods
objectName.methodName()
Example
- var person = {
- age: 59,
- address: "Delhi",
- fullName: function() {
- console.log('John Doe');
- return 'John Doe';
- }
- };
person.fullName
- // function () {console.log('John Doe'); return 'John Doe';}
- Otherwise it’ ll execute the method
- person.fullName();
- // John Doe
Loop over all properties in Object
- for(a in person){console.log(a)}
- age
- address
- fullName
Q: How do you add/delete properties to existing object?
Ex
- person.country = “India”;
To delete you could use the delete keyword
- delete person.age;
Access operator

Q: Can you access a property, which does not exist in Object?
Ex
- person.lastName;
- //undefined
Q: Can you access a method, which does not exist in Object?
Ex
- person.lastName();

Read more articles on JavaScript
Hassan ChaabanPosted May 29, 2016, 9:01 AM
Verry clear,nice explanation, i love it
Guest UserPosted May 29, 2016, 2:29 AM
Hi Vinayak, can yuu please tell me which tool are you interested in?
Debasis SahaPosted May 23, 2016, 1:51 PM
Good One..
vinayak ghantiPosted May 22, 2016, 3:15 PM
super i loved it , can you suggest any tool for JS
Amit DavePosted May 3, 2016, 6:56 AM
Nice article!
Upendra Pratap ShahiPosted Apr 30, 2016, 4:01 PM
Thanks @sumit sir...
RakeshPosted Apr 29, 2016, 3:00 PM
Good one sir
Ravi PatelPosted Apr 25, 2016, 9:37 AM
thanks sir. for nice explanation
Vishvajeet PawarPosted Apr 25, 2016, 3:59 AM
good one
Guest UserPosted Apr 24, 2016, 11:03 PM
Thanks Mahesh Chand, I am glad you liked the title!
Mahesh ChandPosted Apr 24, 2016, 9:59 PM
Nice Sumit. I like title Voice of a Developer :)
Kumaresh RajalingamPosted Apr 24, 2016, 9:35 PM
Nice share
Rahul Kumar SaxenaPosted Apr 24, 2016, 12:20 PM
Good One
Vignesh ManiPosted Apr 24, 2016, 9:50 AM
Good one
Vignesh ManiPosted Apr 24, 2016, 9:50 AM
Nice one
Guest UserPosted Apr 24, 2016, 12:32 AM
Thanks guys!
Bhuvanesh MohankumarPosted Apr 23, 2016, 6:20 PM
Good
Kuppurasu NagarajPosted Apr 23, 2016, 1:31 PM
Nice Sharing..
Upendra Pratap ShahiPosted Apr 23, 2016, 9:35 AM
nice explain sir...