You get a bonus - 1 coin for daily activity. Now you have 1 coin

JAVASCRIPT and jquery questions and answers to the interview

Lecture



1. if possible, implement both js and jquery and change the image of this picture
<img src = 'logo.png' id = 'idlogo' />
2. if possible, implement both on js and jquery. given an array of two elements. add third
3. Contact DOM and get list items . if possible, implement both js and jquery.
4. Write a function to add a CSS class to an element . if possible, implement both js and jquery.
5. write an ajax request and send post data in it
1. How to redirect the page to javascript?
<script type = ”text / javascript”>
<! -
window.location = “http://www.google.com/”
// ->
</ script>
2. How to display in JavaScript a number that will change, for example, every second?
hey = 1;
function foo () {
document.write (hey);
hey ++;
}
setInterval (“foo ()”, 1000);
3. How many parameters can I pass to the function?
How much you want.
4. It is necessary to output some message by an alert, 3 seconds after the launch of the script. How to do it?
So:
setTimeout ('alert (“Hello', 3000);
Or so:
setTimeout (function () {alert (“Hello”)}, 3000);
5. How does inheritance in JavaScript differ from inheritance in PHP?
Unlike PHP, where inheritance can be done in one way, in JavaScript such methods
lot. At the language level, inheritance on prototypes is implemented.
In JavaScript, each object can be associated with another object — the so-called “pro-
totype ”(prototype). In case the search for some property (or method) in the source object
fails, the interpreter tries to find a property of the same name (method) in its
prototype, then in the prototype prototype, etc. For example, if we requested an appeal to
obj.prop (or, exactly the same thing, obj ['prop']), JavaScript will start looking for the prop property in
the obj object itself, then in the prototype obj, the prototype of the obj prototype, and so on.
6. Give an example of inheritance in JavaScript.
For example, let the object “wolf” be inherited from the object “animal”.
Inheritance on prototypes is implemented as a reference.
wolf.prototype = animal;
Or here is a slightly more detailed example. MyType is inherited from Obj:
Obj = {
x: “1”
}
// create the Obj object and write the x = 1 property into it.
MyType = function () {
}
// create an empty MyType object.
MyType.prototype = Obj; // inherit MyType from Obj.
newObj = new MyType ();
document.write (newObj.x);
7. A few words about objects in javascript?
Objects (they are also associative arrays, hashes) and working with them in JavaScript is not implemented
as in most languages. Many mistakes and misunderstandings are connected with this.
An object in JavaScript is a regular associative array or, in other words, a “hash”.
It stores any “key => value” matches and has several standard methods.

8. What is the object method in JavaScript?
The object method in JavaScript is simply a function that is added to the associative array.
9. Why in var JavaScript before the variable?
If you create a variable through ordinary assignment, a “global variable will be created
naya. ”
Example:
max = 100;
If you create a variable using the word var, then a “local peer
variable ”, which ceases to exist after the function is completed.
Example:
var max = 100;
10. There are two functions:
function f (a, b) {return a + b}
and
var f = function (a, b) {return a + b}
Is there any difference between them? If there is what?
There is a difference in the visibility of the function. The variant of the function without var is visible everywhere in the current area.
visibility. Including up to the definition of the function. The var variant assigns the function
variable, so this function is visible only after the definition.
11. How to create an array in javascript?
var array = [elem0, elem1, elem2];
var empty = [];
var array = new Array (elem0, elem1, elem2);
var empty = new Array ();
12. Is it possible to use a function as a constructor in JavaScript?
Yes. Like this:
var A = function () {
something here
}
var myA = newA ();
13. How many and what constructions for loops are there in javascript?
Three: for, while and do ... while.
14. What the code does: break me_baby; ?
Exit the current block of the cycle or switch to the “me_baby” label.
15. Is it possible to set an array like this: var a = “a, b” .split (',')?
Yes you can.
7. JQUERY
1. How to connect jQuery to a web page?
<head>
<script type = 'text / javascript' src = 'jquery.js'> </ script>
</ head>
2. What is the general meaning of jQuery? Why is it necessary?
The essence of jQuery is to select elements of HTML pages and perform certain actions on them.
3. Select all items with id = idname
$ ('# idname');
4. Select all div elements with id = idname
$ ('div # idname');
5. Select all items with class = classname
$ ('. classname');
6. Select all div elements with class = classname
$ ('div.classname');
7. Select all the span elements in the div elements.
$ ('div span');
or so:
$ ('div'). find ('span');
8. Select all div and span elements.
$ ('div, span');
9. Select previous item from found
$ ('# banner'). prev ();
10. Select the next item from that found.
$ ('# banner'). next ();
11. Select all the span elements in the div elements, where the span is a direct descendant of the div.
$ ('div> span');
12. Select all span after the first div element.
$ ('div ~ span');
13. Choose first li in ul
$ ('ul li: first-child');
14. Choose divs that have no cls class
$ ('div: not (.cls)');
15. Select elements with active animation.
$ ('div: animated');
16. Select the divs that contain the firstclass class and the secondclass class.
$ ('div.firstclass'). filter ('. secondclass');
17. Select all divs with title = test attribute
$ (“Div [title = 'test']”);
18. Select all checked checkboxes.
$ ('input: checked');
20. What is a Document Object Model (DOM)?
It is a platform and language independent programming interface that allows programs
and scripts to access the contents of HTML and XML documents, as well as change the content
press, structure and execution of such documents

Comments


To leave a comment
If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Scripting client side JavaScript, jqvery, BackBone

Terms: Scripting client side JavaScript, jqvery, BackBone