1. Question:

    What do you mean by Array? How will you declare an array?

     

    Answer
    Array
    1. Array is a compound data structure in computing.
    2. It is as a collection of numbered variable.

    An array in javaScript have the following general syntax to declare:

    1. var a=new Array();
    2. var a=[];


    1. Report
  2. Question:What is the difference between “==” and “===” operator? 

    Answer

    1. Both are comparison operators but
    2. "==" test for equally operator compares its operands with only value ignoring the datatype.
    3. Whereas "===" test for strict equally operator compares its operands with datatypes and the value.

    1. Report
  3. Question:What do you mean by “with” statements? Write it’s syntax. 

    Answer

    With statement:


    1. JavaScript’s with statement was intended to provide a shorthand for writing recurring accesses to objects.
    2. Instead of having to list all of the properties of an object by repeating the basic object, we can state the bulk of the object in a with statement and then the properties within the context of the with statment.

    Syntax:
    with (object){
      statement
    }

    Example:
    var a, x, y;
    var r = 10;
    with (Math) {
      a = PI * r * r;
      x = r * cos(PI);
      y = r * sin(PI / 2);
    }

    1. Report
  4. Question:Briefly describe JavaScript core Array method pop() with an example. 

    Answer
    Array.pop() method removes the last element of an array and returns it.Example:
    var stackWork=new Array("Lenny","Harold","Mary","Jean","Sal");
      var item=stackWork.pop();
      document.write(item);
      document.write("<br/>")
      document.write(stackWork);
    Output: Sal Lenny,Harold,Mary,Jean

    1. Report
  5. Question:Briefly describe JavaScript core Array method push() with an example. 

    Answer
    Array.push() method add a value to the end of the array (top of the stack) and leaves it there.Example:
    var stackWork=new Array("Lenny","Harold","Mary","Jean","Sal");
      stackWork.push("Delia");
      document.write(stackWork);
    Output: Lenny,Harold,Mary,Jean,Sal,Delia

    1. Report
  6. Question:Briefly describe JavaScript core Array method shift() with an example. 

    Answer
    Array.shift() method removes the first element in an array and returns it.Example:
    var stackWork=new Array("Lenny","Harold","Mary","Jean","Sal");
      var item=stackWork.shift();
      document.write(item);
      document.write("<br/>")
      document.write(stackWork);
    Output: Lenny Harold,Mary,Jean,Sal,Delia

    1. Report
  7. Question:Briefly describe JavaScript core Array method unshift() with an example. 

    Answer
    Array.unshift() method is similar to the push() method, except that the new element is put at the front of the array (bottom of the stack) and it returns the current length of the array.Example:
    var stackWork=new Array("Lenny","Harold","Mary","Jean","Sal");
      var item=stackWork.unshift("Willie");
      document.write(item);
      document.write("<br/>")
      document.write(stackWork);
    Output: 6 Willie,Lenny,Harold,Mary,Jean,Sal

    1. Report
  8. Question:Briefly describe JavaScript core Array method splice() with an example. 

    Answer
    Array.splice() is a method used to insert, delete, and substitute values in array elements. The method has three arguments, start, delete, and data. The starting position specifies where the new value (data) is to be inserted and where deletions begin. If no deletions are specified, the splice() method has the effect of inserting an element and value into an array.Example:
    var stackWork=new Array("Lenny","Harold","Mary","Jean","Sal");
     stackWork.splice(1,0,"Fred");  
     document.write(stackWork);
    Output: Lenny,Fred,Harold,Mary,Jean,Sal

    1. Report
Copyright © 2024. Powered by Intellect Software Ltd