top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is Strict Mode and Push() method in JavaScript?

+2 votes
407 views
What is Strict Mode and Push() method in JavaScript?
posted Jun 17, 2014 by Ritika

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Strict Mode:

  • The fifth edition of ECMAScript specification has introduced Script Mode.-Strict Mode applies a layer of constraint on JavaScript.
  • It throws errors for actions that are problematic and didn’t throw an error before.
  • It throws errors for the actions which are potentially unsafe.
  • It shut downs the functions which are poorly thought out.
  • Strict mode solves mistakes that are responsible for the difficulty of JavaScript engines to perform optimizations.
  • To enable the strict mode we have to add the string literal “use strict” on the top of file or function as follow:

    function myfunction()
    {
    “use strict";
    var v = “I am a strict mode function";
    }

Push Method: The push() method is used to append one or more elements to the end of an array.

For example:

var fruits = [ "apple" ];
fruits.push( "banana" );
fruits.push( "mango", "strawberry” );
console.log(fruits);

we get the following console output:

["apple ", "banana ", "mango ", "strawberry "]

Using Push() method we can also append multiple elements by passing multiple arguments.
The elements will be appended in the order of they are inserted i.e. left to right.

answer Jun 18, 2014 by Saif Khanam
...