ES5 Features

Major features introduced in ECMAScript 5

    1. It’s okay to have trailing commas in object literals. Since beginning javascript allowed trailing commas in the array.
      var obj = { 'name': 'Commands Tech', 'category': 'tech new', }

      However, using trailing commas in JSON is invalid and throws the error.

      var myJSON = '{"name":"CommandsTech", "city":"New York",}';
      VM793:1 Uncaught SyntaxError: Unexpected token } in JSON at position 42
      at JSON.parse (<anonymous>)
      at <anonymous>:2:6
    2. No reserved keywords for variable names.  Reserved keywords should not be used as variable names. Example:
      var NaN = 'CommandsTech';
      console.log(NaN); // NaN
    3. parseInt() defaults to radix 10

    4. JSON.parse() & JSON.stringify()

      JSON.parse(): To convert text into a javascript object
      JSON.stringify(): To convert a javascript object into string

    5. bind()

      Description:  Bind method allows us to call a function with this set explicit. bind method returns a bounded function with the bound object.

      this.x = 10;
      var moduleX = {
      	x : 20,
      	getX: function() { return this.x; }
      var retriveX = moduleX.getX;
      var getBoundX = retriveX.bind(moduleX);
      Output: 20
    6. trim()

      Description: Removes whitespace on both ends of the string and returns a string

      var name = ' commandsTech ';
    7.  every()

      Description: method takes a function as input parameter and checks if each element in an array passes the test and return a boolean

      var bills = [132, 233, 916, 140];
      function checkBills(bill) {
      return bill >= 100;
      bills.every(checkBills); // Output true
    8.  filter()

      Description:  method creates a new array with all elements that pass a test implemented by the provided function

    9. map()

      Description:  method creates a new array with the result of calling a provided function on each element. 

  1. forEach()

    Description: method calling a provided function on every array element.

  2. reduce()

    Description: reduce method results in a single value that is a result of calling a reducer function on each element.
    filter, map, forEach, map method examples


    Description:  returns the current time

  4. Date.prototype.toISOString

  5. new Date(string) and Date.parse(string)

  6. Object.keys()

    Description: Fetch all the keys() present in an object. Object.keys() method returns an array of own properties

    const profile = {
    name: 'commandsTech',
    location: 'Hyd',
    console.log(Object.keys(profile)); // ['nane','location']
  7. Object.create()
    Description: Create a new object taking the existing object’s prototype

    var profile = {
    name: 'commandsTech'
    var profile2 = Object.create(profile);; // output: "commandsTech"
  8. Object.defineProperty & Object.defineProperties
    Description: Using defineProperties we can modify or define properties on an object.

    const profile = {};
    Object.defineProperties(profile, {
    name: {
    value: 'commandsTech',
    writable: true
    // expected output: commandsTech
  9. Object.getOwnPropertyDescriptor()

    Descriptor: Using this method we can know the description of the property specified within the object

    var profile = {
    location: "hyd"
    var descriptor = Object.getOwnPropertyDescriptor(profile, 'name');
    console.log(descriptor.configurable); // output: true
  10. Object.getOwnPropertyNames(obj)

    Description: All the properties present on an object are returned

    var profile = {
    location: "hyd"
    Object.getOwnPropertyNames(profile); // output ['name', 'location']
  11. Object.seal()

    Description: the seal on object prevents adding of new properties and marks all existing as non-configurable properties. Values of a property can be changed(if writable).
    const profile = {
    name: 'commandsTech'
  12. Object.freeze()

    Description: Object that is frozen cannot be changed. The freeze prevents adding new property & deleting the existing property. Prevents changing the enumerability, configurability or writability or changing. Changing of the prototype is also prevented on the frozen object.

    const profile = {
    name: 'commandsTech'
  13. Object.isSealed()

    Description: Checks if an object is sealed or not

    const profile = {
    name: 'commandsTech'
    console.log(Object.isSealed(profile)); //output: false
    console.log(Object.isSealed(profile)); // output: true
  14. Object.isFrozen()
    Description: Checks if an object is frozen or not

    const profile = {
    name: 'commandsTech'
    console.log(Object.isFrozen(profile)); //output: false
    console.log(Object.isFrozen(profile)); // output: true
  15.  Property Attributes: writeable, value, enumerable, configurable, get, set.
  16. ‘use strict’;

    Description: Use strict indicates that javascript code should be executed in “strict mode”.

    Example with use strict

    "use strict";
    name = 'commandsTech'; // This will throws an error (name is not defined).

    Example without use strict

    name = 'commandsTech'; // This will not throw an error even though name is not defined

Leave a Reply

Your email address will not be published. Required fields are marked *