1. What is
JavaScript and what are the advantages to use it???
a.
JavaScript
is the Programming Language for the Web. The code is writing
in the client side.
b.
JavaScript
can update and change both HTML and CSS.
c.
JavaScript
can calculate, manipulate and validate data.
d.
Form
validation can be done in client side which is reduce the un-necessary round
trip between the client and server. So load on the server is reduced.
e.
JavaScript
now is also server side language (Using nodes).
f.
JavaScript
is developed by Netscape Company which is a software company.
g.
JavaScript
is Case-Sensitive.(can not write Alert();)
2. JavaScript
Data Types:
a.
Number
b.
String
c.
Boolean
d.
Array
e.
Object
f.
Array
g.
Undefined.
EXAMPLES:1 (Number/String/Boolean)
var length = 16; // Number
var lastName = "Johnson"; // String
var x = {firstName:"John", lastName:"Doe"}; // Object
var x = 16 + "Volvo"; // Result : 16Volvo.
var x = “Volvo” + 16; // Result : Volvo16
var x = 16 + 4 + "Volvo"; // Result : 20Volvo
var x = "Volvo" + 16 + 4; //
Result : Volvo164
var x; // Now x is undefined
x = 5; // Now x is a Number
x = "John"; // Now x is a String Result: John
var x = 5;
var y = 5;
var z = 6;
(x ==
y) // Returns true
(x ==
z) // Returns false
EXAMPLES:4 ARRAY Declare
var cars = ["Saab", "Volvo", "BMW"];
EXAMPLES:5 OBJECT Declare
var x = {firstName:"John", lastName:"Doe"};
EXAMPLES:6 Undefined
var car; // Value is undefined, type is undefined
3. What is NaN and
isNaN?
a.
NaN(Not a number)
b.
The NaN property
represents "Not-a-Number" value. This property indicates that a value
is not a legal number.
c.
isNaN(123) //false
isNaN(-1.23) //false
isNaN(5-2) //false
isNaN(0) //false
isNaN('123') //false
isNaN('Hello') //true
isNaN('2005/12/12') //true
isNaN('') //false
isNaN(true) //false
isNaN(undefined) //true
isNaN('NaN') //true
isNaN(NaN) //true
isNaN(0 / 0) //true
isNaN(null) //false
d.
4. What are all
looping in JavaScript?
a.
For loop
b.
While loop
c.
Do while loop.
5. How to Convert
String to Integer and string to Float.
a.
ParseInt
b.
ParseFloat.
c.
Example :
var a =
"100"; //This is a string
var b =
parseInt(a);
document.write("Integer
value is"
+ b); // Result=100 a
integer value.
6. Function in JavaScript.
Type of functions??
//defining a function
function function_name()
{
// code to be executed
};
//calling a function
Function_name();
EX:
var x = myFunction(4, 3); // Function is called, return value will
end up in x
function myFunction(a, b)
{
return a * b; // Function returns the product of a and
}
Result :12
7. Error Handling
in JavaScript. (Try/Catch/Finally/Throw)
a. EX:
8.
Live Demo
9. <html>
10. <head>
11.
12. <script type = "text/javascript">
13. <!--
14. function myFunc() {
15. var a = 100;
16. var b = 0;
17.
18. try {
19. if ( b == 0 ) {
20. throw( "Divide by zero
error." );
21. } else {
22. var c = a / b;
23. }
24. }
25. catch ( e ) {
26. alert("Error: " + e );
27. }
28. }
29. //-->
30. </script>
31.
32. </head>
33. <body>
34. <p>Click the following to
see the result:</p>
35.
36. <form>
37. <input type = "button"
value
=
"Click Me" onclick = "myFunc();" />
38. </form>
39.
40. </body>
41. </html>
42. Events in Java
Script.
43. Regular
expression in JS. How to use it.
44. OOP and Object
in JS.
45. Private members
in JS.
46. Properties in
JS. (Accessing via set and get methods)
a.
Read/Write
b.
Read only
c.
Write only.
47. Static members
in JS.
a.
Like static float pi=3.141F
48. What are the
different between “==” and “===”.
a.
The == operator
checks equality only whereas === checks equality, and data type, i.e., a value
must be of the same type.
49. Java scrip is a
static typed or dynamic typed Language.
a.
Answer: Dynamic typed.
50. What is DOM
what is use of this???
a.
DOM stands for document object model. A documents
model represents the HTML documents. It can be used to implements the code
and change the HTML contents .
51. What is use of
window object ?
a.
It is define in the browser, that represents the
window of a browser. It I a browser object.
b.
52. What are the
Pop Up Boxes in Java Script
a.
Alert Box.
b.
Confirm Box.
c.
Prompt Box.
a)
Alert BOX
When
an alert box pops up, the user will have to click "OK" to proceed.
a) Confirm
Box:
When a confirm box pops up, the user will have to click either
"OK" or "Cancel" to proceed.
If the user clicks "OK", the box returns true. If the user
clicks "Cancel", the box returns false
b) Prompt
Box
When a prompt box pops up, the user will have to click either
"OK" or "Cancel" to proceed after entering an input value.
If the user clicks "OK" the box returns the input value.
If the user clicks "Cancel" the box returns null.
53. What is closure
and how do you use it?
a.
When
a function returns the other function the returning function will hold its
environment and this is known as closure.
54. How can create
a object in Java script?
a.
JavaScript
objects are written with curly braces {}
.
b.
Var object = { Name: “Ujjwal”, Age:29, Number:
8888888888 };
EX:
c.
<!DOCTYPE html>
d.
<html>
e.
<body>
f.
g.
<h2>JavaScript Objects</h2>
h.
i.
<p id="demo"></p>
j.
k.
<script>
l.
var person = {
m.
firstName : "John",
n.
lastName
: "Doe",
o.
age : 50,
p.
eyeColor
: "blue"
q.
};
r.
s.
document.getElementById("demo").innerHTML
=
t.
person.firstName + " is " + person.age
+ " years old.";
u.
</script>
v.
w.
</body>
x.
</html>
HOME BACK |
No comments:
Post a Comment