Tuesday, April 26, 2016

Javascript


What is a Javascript
  • Javascript is a client side scripting language which is used for performing client side web development.
  • Javascript functions can be placed either in body tag or head yag.
  • In order to reuse Javascript validations in all pages we need to place javascript code in a js file and refer the js file in web pages.
How do we add a Javascript on a Web page
  • We can add a Javascript on web pages by two ways
  • If a javascript code is very small then we need to perform in a web pages.
  • If a javascript code is very large then we need to add it in a separate file and use the file reference in web pages.

    Example:<script type="Text/Javascript" src="js file path"/>
What is difference between "==" and "===" in javascript
  • "==" checks for Equality
  • "+++" checks for Equality as well as Type(data type).
How to access the Textbox value in Javascript
  • var name=document.getElementById("textboxid").value;
What are Javascript types

  • Number,String,Boolean,Function,Object,Null and Undefined are Javascript types.
What are Undeclared and Undefined Variables
  • Undeclared variables are one which does not exists in a program and if we tries to read the value of undeclared variables then we get a runtime error.
  • Undefined variables are those that are declared in a program but not been initialized a value.If a programmer tries to read a value of undefined variable then undefined value is returned.

How to create an Array in Javascript
  • var names=new Array("Vikas","venkat");
    var idata=names[0];
What is the use of ISNAN function in javascript
  • ISNAN: Full form of ISNAN is Isnot a Number.This function returns true if it is not a number else returns false. 
  • Example: ISNAN("Venkat");  It returns true
What does "5" +6+7 evaluates 
  • Since first digit "5" is a string then every thing will be Concatenated(Combined).
  • Output is 567.
What does 2+3+"4" evaluates
  • Since first two numbers are integer it will be added and concatenated with thrid digit as it is a string.
  • Output is 54.
How to create an elements dynamically using Javascript
  • var tdivid=document.getElementById("divid"); // first getting div id
    for(i=0;i<9;i++)
    {
    var input=document.createElement("input");  // creating input element
    input.type="text";                                            // creating attributes for input element
    input.name="name" + i;
    tdivid.appendChild(input);                            //Appending element to div
    tdivid.appendChild(document.createElement("br")); //creating element  for a new line
    }
What is difference between alert and confirmation box
  • alert displays only one OK button where as Confirmation box is used to display two buttons with OK and Cancel.It returns a boolean value true or false
Where should Script tag should be placed
  • Script tag should be placed in body tag as in some cases javascript code will not work if we place it in head tag.
  • Example: If we set Textbox background color it works in body tag but it will not work in head tag because at that time elements will not be loaded in browser DOM.
What is Push in Javascript
  • Push: This method adds a new item to the end of an array and it can also increase the length of any array.
What is Pop in Javascript
  • Pop: It removes the last element from the array,returns that element and it also returns the length of an array.
What is Unshift in Javascript
  • Unshift: It adds an new item to the beginning of an array.
What is Shift keyword in Javascript
  • Shift:It removes the first item from an array and returns the array.
What is Slice in Javascript
  • Slice:This method returns the selected items from an array.
   What is a Mutator Method
  • Mutator Methods: Some methods modifies an array elements where as some methods will not modify the array elements.Methods which modifies an array elements are called as Mutator elements.
  • Example:Push,Pop and Unshift are Mutator elements.
What is a Closure in Javascript
  • Closure is nothing but adding a function inside another function is a Closure.
  • A closure is a inner function which can access outer function variables and can also access the outer function parameters.
Difference between Window.Open() and window.showmodaldialog in javascript
  • Window.Showmodaldialog opens up a modal window(Child window) which cannot loose the focus until window is close and we cannot access the parent window until child window is closed.
  • Window.open opens a window just like a browser window and we can also access the parent window even child window is not closed.
Difference between Page.Registerclientscriptblock and Page.Registerstartupscript
  • Both are the methods of a ScriptManager.Both are used to insert a client script dynamically in a web page.

RegisterClientscriptblock
Registerstartupscript
This method adds the javascript to the web page after the "<form>" opening tag. This method adds the javascript to the web page after the "<form>" closing tag.
We cannot access the html elements as elements are not been initialised We can access the Html elements as all the elements are initialised.

What is a Prompt box

  • Prompt box is a box which allows the user to enter input by providing a textbox.
What is a "this" Keyword in a Javascript

  • "this" keyword is used to point to a current object in the code. (or) it refers to an object from where it is called
How can we submit a form using javascript
  • document.form[0].submit() is sued to submit the form
What is Variable typing in Javascript

  • Variable typing is used to assign a number to a variable and to the same variable it can be assigned to a string.
  • Example:Var i=10; i="venkat";
How to detect an Operating system on the client machine

  • navigator.appVersion is used to detect the operating system on client machine.
What is a Prototype in Javascript

  • Let us assume we have a function with name getname and we want to invoke a function.To do this we will create an object.Let say if we create 100 objects then there will be a 100 copies of getname function.
  • If we don't want to create the copies of the function and if we want all the object to share the one copy of getname function then we make use of Prototype which is nothing but a Prototype





No comments:

Post a Comment