JavaScript Questions & Answers

1)    What is JavaScript?
Javascript is client side scripting Language that have the object oriented capabilities and It is light weighted language and through this we can easily play with DOM elements

2)    What are the datatypes supported in JavaScript?
JavaScript supports almost all data types used in C# and below are the list
·         Number
·         String
·         Boolean
·         Undefined
·         Null
·         Object

3)    What are the advantages of JavaScript?
·         Through JavaScript, We can validate webpage in client side and no need to send it to Server Side
·         JavaScript is lightweight so the response is quick
·         JavaScript are used to give a rich interface to provide the functionality like drag and drop components,

4)    How can we use JavaScript?
JavaScript can be used as like suppose you have to assign a data to a variable
var Name= “Kamal”;
In JavaScript, we have to “var” to declare a type of data
Support you want to create an object of data
var lstStudent =  {
Name : “Ajay”,
Age: 33
} ;

5)    Is JavaScript case-sensitive language?
Yes, JavaScript is case-sensitive so always try to follow a Nomenclature while declaring a variable.

6)    How can we write JavaScript Code to start?
We can write code in <head> tags and can include JavaScript file into it.
For creating a function in JavaScript , just use function and the function Name as below
example
Prototype
function functionName(parameters ){
// Logic here
 }

Real Example
function GetName(var status){
if (status==0){
// do this
}
else
{
//do that
}
}

JavaScript code is written by two ways as follows
Inline
            <head>
                        <script>
        function CallMethod() {
            //code for this method
        }
                        </script>
            </head>           
JavaScript file
            <head>
<script src="~/Content/js/Alert.js"></script>
            </head>           

7)    How can we create Array in JavaScript?
For creating an array , we have to declare by as below
var y= []; 
assigning the elements
var mm= [1,3,5,7,9];
adding more elements to array
                           mm.push(10);


8)    What are the important function names used to get elements from DOM?
There are many functions available as below to get data from DOM as per our need so some of them are as below
getElementById- if you want to get element by ID then use this by as
document.getElementById("articles-3")

getElementsByName - if you want to get element by Name then use this by as
document.getElementsByName(“txtName”)

getElementsByClassName - if you want to get element by Class NAme then use this by as
document.getElementsByClassName(“btnClass”)

getElementsByTagName - if you want to get element by Tag Name then use this by as
document.getElementsByTagName(“rounded”)

9)    What is the difference between null and undefined in JavaScript?
·         undefined means variable is declared but not yet assigned but null itself a value
·         null means no value for that variable but unassigned itself a type in JavaScript so it show a  values itself

10) What is the differences between “===” , “==” and “=” in JavaScript?
“=” is used to assigning a value to variable
var x="ajay"

“==” is used to Compare two Values irrespective of their type
       var a= 13
       (a==x)    will give false
“===” is used Compare two Values and strict to their type also
            var x="ajay"
       var y="ajay1"
       var z="ajay";
x===z   will give true as type and content also same
x===y  will give false but type is same but content is different



Companies Question/Answers Set -1

1.     Basics pillars of OOPs? 2.     What are the use of new keyword in overriding? 3.     What is the difference between abstra...

Powered by Blogger.