1. Question:What is history object? Write methods of it. 

    Answer

    history object: 1. The history object is a property of the window object. It has a single property name length.
    2. The history object contains the URLs visited by the user (within a browser window).

    functions: 1. back() - Loads the previous URL in the history list.
    2. forward() - Loads the next URL in the history list.
    3. go() - Loads a specific URL from the history list.

    1. Report
  2. Question:

    What do you mean by cookies?

     

    Answer

    Cookie:

    1. A cookie is usually a small piece of data sent from a website and stored in a user's web browser while a user is browsing a website.
    2. When the user browses the same website in the future, the data stored in the cookie can be retrieved by the website to notify the website of the user's previous activity.
    3. Cookies were designed to be a reliable mechanism for websites to remember the state of the website or activity the user had taken in the past

    The general format for setting a cookie is this:

    document.cookie=value;[expires];[path];[domain];[secure];

    1. Report
  3. Question:What is reserved word? Write five reserved word. 

    Answer

    1. Reserved words are those in JavaScript that have been reserved for statements and bulit-in functions.
    2. We should avoid creating identifier for variable and functions that are identical to JavaScript reserved word.

    Five reserved words are:

    1. function
    2. for
    3. return
    4. break
    5. continue

    1. Report
  4. Question:Write about interpreted and loosely typed language according to JavaScript? 

    Answer

    An Interpreted Language:
    The process involves by browser parsing (interpreting) the JavaScript code and then creating an equivalent machine language and execute the interpreted code.

    Loosely typed language: The language that does not require to specify the datatype (int, float, boolean, string etc.) before declaring variables.


    1. Report
  5. Question:What is function? How can you define function in JavaScript? 

    Answer

    Function:


    1. A colloection of statements/code which can perform a specific task and can be executed by an event of call to that function.
    2. We can have a) Built-in function and 2) User-defined functions

    Syntax of defining a function:

    function functionName(functionParameter list){
     
       statements

    }

    Example:

    function add(a,b){
       return a+b;
    }

    1. Report
  6. 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
  7. 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
  8. 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
  9. 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
  10. 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