get child elements inside div using javascript



    function getChilds()
        var arr=document.getElementById('mess').childNodes, str='';
        for(var i=0; iarr.length; i++) {
            if(arr[i].innerHTML!=undefined) {
                str+=" "+(arr[i].textContent||arr[i].innerText);
        return true;

Object.defineProperty() Javascript

There will be some situations where we should not allow our objects to be override or delete etc. Then we have to use this defineProperty.

The Object.defineProperty() method defines a new property directly on an object, or modifies an existing property on an object, and returns the object.


Object.defineProperty(obj, prop, descriptor)


The object on which to define the property.
The name of the property to be defined or modified.
The descriptor for the property being defined or modified.

When do you use?

Object.defineProperty is mainly used to set properties with specific property descriptors (e.g. read-only (constants), enumerability (to not show a property in a for (.. in ..) loop, getters, setters).

In Javascript, the standard properties (data member with getter and setter described above) are defined by accessor descriptor (in the link you have in your question). Exclusively, you can use data descriptor (so you can’t use i.e. value and set on the same property):

  • accessor descriptor = get + set (see the example above)
    • get must be a function; its return value is used in reading the property; if not specified, the default is undefined, which behaves like a function that returns undefined
    • set must be a function; its parameter is filled with RHS in assigning a value to property; if not specified, the default is undefined, which behaves like an empty function
  • data descriptor = value + writable (see the example below)
    • value default undefined; if writable, configurable and enumerable (see below) are true, the property behaves like an ordinary data field
    • writable – default false; if not true, the property is read only; attempt to write is ignored without error*!

Both descriptors can have these members:

  • configurable – default false; if not true, the property can’t be deleted; attempt to delete is ignored without error*!
  • enumerable – default false; if true, it will be iterated in for(var i in theObject); if false, it will not be iterated, but it is still accessible as public

* unless in strict mode – in that case JS stops execution with TypeError unless it is caught in try-catch block


var createPerson = function(firstName,lastName){
var person = {};
return person;

var person = createPerson(“sathya”,”vakacharla”);

Instead you can use object.defineProperties to set properties for firstName and lastName at a time.,

Null Vs Undefined Javascript

In JavaScript, undefined means a variable has been declared but has not yet been assigned a value, such as:

 var TestVar;
 alert(TestVar); //shows undefined
 alert(typeof TestVar); //shows undefined

null is an assignment value. It can be assigned to a variable as a representation of no value:

 var TestVar = null;
 alert(TestVar); //shows null
 alert(typeof TestVar); //shows object

From the preceding examples, it is clear that undefined and null are two distinct types: undefinedis a type itself (undefined) while null is an object.

Unassigned variables are initialized by JavaScript with a default value of undefined. JavaScript never sets a value to null. That must be done programmatically.

 null === undefined // false
 null == undefined // true
 null === null // true


 null = 'value' // ReferenceError
 undefined = 'value' // 'value'