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, 5:01 AM EDT
Verry clear,nice explanation, i love it
Guest UserPosted May 28, 2016, 10:29 PM EDT
Hi Vinayak, can yuu please tell me which tool are you interested in?
Debasis SahaTOP 100Posted May 23, 2016, 9:51 AM EDT
Good One..
vinayak ghantiPosted May 22, 2016, 11:15 AM EDT
super i loved it , can you suggest any tool for JS
Amit DavePosted May 3, 2016, 2:56 AM EDT
Nice article!
Upendra Pratap ShahiPosted Apr 30, 2016, 12:01 PM EDT
Thanks @sumit sir...
RakeshPosted Apr 29, 2016, 11:00 AM EDT
Good one sir
Ravi PatelPosted Apr 25, 2016, 5:37 AM EDT
thanks sir. for nice explanation
Vishvajeet PawarPosted Apr 24, 2016, 11:59 PM EDT
good one
Guest UserPosted Apr 24, 2016, 7:03 PM EDT
Thanks Mahesh Chand, I am glad you liked the title!
Mahesh ChandTOP 10Posted Apr 24, 2016, 5:59 PM EDT
Nice Sumit. I like title Voice of a Developer :)
Kumaresh RajalingamPosted Apr 24, 2016, 5:35 PM EDT
Nice share
Rahul Kumar SaxenaTOP 100Posted Apr 24, 2016, 8:20 AM EDT
Good One
Vignesh ManiTOP 100Posted Apr 24, 2016, 5:50 AM EDT
Good one
Vignesh ManiTOP 100Posted Apr 24, 2016, 5:50 AM EDT
Nice one
Guest UserPosted Apr 23, 2016, 8:32 PM EDT
Thanks guys!
Bhuvanesh MohankumarPosted Apr 23, 2016, 2:20 PM EDT
Good
Kuppurasu NagarajTOP 100Posted Apr 23, 2016, 9:31 AM EDT
Nice Sharing..
Upendra Pratap ShahiPosted Apr 23, 2016, 5:35 AM EDT
nice explain sir...