-
-
] programming language, loosely typed, uses c like syntax, interpreted, based upon ?lisp? ] creator Brendan Eich(@netsape), started on the web circa 1996, to manipulate html/dom in the browser, grew exponentially, ubiqutious,
-
] Ans:JavaScript is a scripting language most often used for client-side web development.
-
] what is the difference between javascript and jscript?
-
] jscript is msft implementation of the javascript specification(ecmascript), each brower vendor creates it own implementation of the ecmascript standard (current v= ?262.5?)
-
] Ans:Both JavaScript and Jscript are almost similar. JavaScript was developed by Netscape. Microsoft reverse engineered Javascript and called it JScript.
-
] how do we add javascript onto a web page?
-
] write a js file then link that file to your page<head> <script type="text/javascript "src="path"/> </head> OR before the closing body tag // ] write a js script inside of the head of your page // ] write a js script inline inside the body of the page using <script> tags
-
] for short single use scripts put in head of your page, for larger scripts, write a js files and link
-
] is javascript case sensitive?
-
] yes - js is very sensitive,
-
] yes - getElementById IS NOT the same as getElementByID
-
] What are the 'types' used in javascript?
-
] String, Number, Math, Array, Function, Boolean, Object, RegEx ?? ( Null, Undefined ) Array type ??
-
] Ans:String, Number, Boolean, Function, Object, Null, Undefined.
-
?? ] What art the boolean operators supported by the js AND operator &&
-
] x < 10 && ( >,<, ===, !===, )
-
] OR operator || NOT operator - !
-
] What is the difference between == and ===
-
] == can cause problems because ..., always use ===
-
] == checks for equality only, === checks for equality and type
-
] how to access the value of a textbox using javascript?
-
] var textBoxValue = getElementById('textboxid').value; // document.getElementById
-
] document.getElementById(...) //
-
] What are the ways of making comments in js?
-
] // single line, /* multi line */
-
] // line comments /* block comments */
-
x] how will you get the checkbox status, wether it is checked or not?
-
] if (document.getElementById('checkBox1').checked === 'checked' ) {alert("checked");}else{alert("not checked");} // value = true, // ] $("checkBox").val('true')
-
] document.getElementById('checkBox1').checked returns true OR false
-
] how to create arrays in javascript?
-
] var cats = new Array("chester","harly","carly"); // object literal var cats = ["chester","harly","carly"] // var cats = new Array(); cats[0] = "chester";
-
] If an array with name as "names" contain three elements, then how will you print the third element of this array?
- ] alert(names[2]);
- ] Ans: Print third array element
document.write(names[2]);
-
] How do you submit a form using JavaScript?
-
] document.getElementById('idForm').submit() // $('idForm').submit()
-
] Ans:Use document.forms[0].submit();
-
] what does the 'isNan' function do?
-
] determines if a value is a Number type or not
-
] It returns true if the argument is not a number.
-
] What is the use of Math Object in JavaScript?
-
] Math is a native js object that contains a collection of Mathematical functions you can use in your program, var randomNumber = Math.Random();
-
] The math object provides you properties and methods for mathematical constants and functions
-
] What do you understand by this keyword in JavaScript?
-
] this is a js keyword, you can use 'this' as a shortcut to reference the 'currently in scope' object's properties and methods, its invaluable b/c it enables you to id which option (of any number of options) that is currently active/selected by user
-
] Ans: In JavaScript the this is a context-pointer and not an object pointer. It gives you the top-most context that is placed on the stack. The following gives two different results (in the browser, where by-default the window object is the 0-level context):
-
var obj = { outerWidth : 20 };
function say() {
alert(this.outerWidth);
}
say();say.apply(obj);
-
) What does "1"+2+4 evaluate to?
-
] returns string "124", because "1" is a string, everything is treated as a string
-
] Ans: Since 1 is a string, everything is a string, so the result is 124.
-
] What does 3+4+"7" evaluate to?
-
x] returns 77 because ...
-
Ans: Since 3 and 4 are integers, this is number arithmetic, since 7 is a string, it is concatenation, so 77 is the result.
-
] How do you change the style/class on any element using JavaScript?
-
] document.getElementById('element').setAttribute("class","newClassName");
-
] document.getElementById(“myText”).style.fontSize = “10"; OR document.getElementById(“myText”).className = “anyclass”;
-
X] Does JavaScript support foreach loop?
-
] no
-
] Ans: JavaScript 1.6(ECMAScript 5th Edition) support foreach loop,
-
] What looping structures are there in JavaScript?
-
] for, for each in, for in, for of, do while, while
-
] Ans: for, while, do-while loops
-
] What is an object in JavaScript, give an example?
-
] everything in js is an object, if were talking in the language itself, Number, Date, String, ... are all objects
-
] Ans: An object is just a container for a collection of named values:
-
var man = new Object();
-
man.name = 'Vikas Ahlawat';
-
man.living = true;
-
man.age = 27;
-
] How you will add function as a property in a JavaScript object? Give an example.
-
] man.showAge = function() {alert(this.age);};
-
]
-
] What is the similarity between the 1st and 2nd statement?
-
1st:- var myString = new String('male'); // An object.
-
2nd:- var myStringLiteral = 'male'; // Primitive string value, not an object.
-
] both create a new string object, the 2nd while classified as a Primitive, still has an object wrapper that gives you the String objects functionality (lenght, ...)