Обязательно Flashcards

1
Q

When building a new web site or maintaining one, can you explain some techniques you have used to increase performance?

A

Well, performance… you mean, how fast page is loaded for user, or what?

In order to reduce page loading time we could to few things.

First of all, we have to understand, what step of process takes longest time. Is that connection to server, or loading a lot of heavy files, or execution of JavaScript, that we have to do before page is rendered, or something else.

If to talk about simple and often cases, well, on client side, if on our page we are using pictures, then we could compress them to make them take less memory space, so they will be loaded faster. Also, we must ensure that our code and other files are splitted into chunks of small size, and we are loading only these chunks, that we need at current moment.

On server side, we, for example, can save ofter accessed data into cache, to reduce time we need to send it to user, or, in case if on client side it takes long time to build DOM tree using complex frameworks with lot of JavaScript, then we could prebuild it on server using server side rendering, and then send to client mostly ready to use structure.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What actions have you personally taken on recent projects to increase maintainability of your code?

A

Okay… At first, I am trying to keep same code style, because this makes code reading much easier. This was implemented as on my current workplace, same in my pet projects. This touches indentation, naming, etcetera.

Second, is splitting code into small functional blocks, each of what contains only certain information, and I am trying to avoid code mixing, following first SOLID principle.

All in all, I am trying always remember about SOLID and KISS principles and follow them.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Can you describe your workflow when you create a web page?

A

Well… If we are talking about web page inside existing project with used framework, for example, Vue, then order is next.

First step is page content. This case I am thinking about what should be on the page, and what page structure would be better.

After that I create page file and add all necessary elements or framework components into template, and write JavaScript code. I also add necessary CSS, without which would be impossible to use the page.

Then I test if everything work fine, I add other CSS styles, to make page look pretty.

Finally, I make a short break, and then with fresh look return to the code, looking for possible mistakes or things I could do better.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

If you have 5 different stylesheets, how would you best integrate them into the site?

A

Well… It depends on exact project structure and needs. But if to talk in common, then I see next solutions.

First, most simple. We can just use <link></link> html element in header to directly import all these files.

Second variant. Like first one, but this case we merge all these five files, so we get less requests to server, and lower loading time.

Third. If these styles are used to add styling to framework components, then would make sense to split them into small parts, and then import when component is loaded. This case, we don’t need to load all styles, we can just use small piece.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How would you optimize a website’s assets/resources?

A

Okay… At first, we should remove all assets, what we don’t really need, and load only necessary.

Second, we could load resources asynchronously, to load them in parallel.

Third, we should properly set up caching options, to reduce number of requests to server.

Finally, we can minify all code and style files, and also use compressed pictures.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Describe how you would create a simple slideshow page.

A

Well, that is quite simple thing, I think. At first, I would create page itself and add it into framework router. Then, talking about slideshow…

Let’s imagine, that we have certain list of images in form of list of links. This case I just add an image element on page. I set source of image to first of this links. Then, after interval, I set it as second link, then third, etcetera, until I reach last link. Then I go to first one and everything repeats.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Explain the importance of standards and standards bodies.

A

I think, this is important because this makes us confident in how our code will be working and how certain things should behave. Without standardization, things would be more complex and harder to work with, because code written for one case could not be used everywhere without conflicts.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is Flash of Unstyled Content? How do you avoid FOUC?

A

This is period, when on page loading page content is already loaded, but styles are not, and page is shown without any styles applied to it.

We can avoid it through different mechanisms. First of all, we could put our styles in head directly or put there links to our stylesheets, to make them start loading first.

Also, we can use styles asynchronous loading using “preload” rel attribute value, and defer our main script execution until all these styles are loaded.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Explain some of the pros and cons for CSS animations versus JavaScript animations.

A

Okay. From one side, CSS animations are simple to declare, they are well optimized, so their performance is good, and finally, we can bind them to different states of components, like hover or active, or focus. From another side, CSS animations become quite difficult to use, when we are talking about complex animations, and also we are limited to certain set of effects.

JavaScript animations. Good sides are next: they are agile, because you have more control on process of execution, and we can execute these animations in certain cases, for example on page scrolling, or on click on certain element.
Bad side of JavaScript animations is bad performance. Also, if user disabled JavaScript execution in browser, then JavaScript animations can not work at all.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How did you handle a disagreement with your boss or your collaborator?

A

Well… I have certain set of rules for cases like this. First, this is important to say, that even in case of disagreement, this is necessary to be calm and polite, because rage and rudeness don’t help to solve the situation.

Well, first situation is disagreement with boss. This case, at first, I am trying to get more information about boss point of view. Maybe, I just don’t know enough, and that is the reason. On next step, if I still have disagreement, I am trying to describe my position pros and cons as fully, as only possible, because maybe just my opponent don’t understand what I want to do, and thinks about something different, and that is the source of the problem. And if anyway we didn’t reach consensus, then I usually just do as my boss told me.

If to talk about dispute with my colleagues, then, I do step one and two as I described in first case, but then if we not reached agreement, I usually go and ask somebody more experienced in dispute sphere to look on our situation and tell us what to do here.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What skills are needed to be a good front-end developer?

A

Well… First of all, in order to be good developer, you need to be able to work with other people on good level, because only through cooperation is possible to do something really big and valuable. You have to be polite, stay calm, and never be rude.

Second moment is personal traits. Good developer is developer who is patient and attentive to details. You have to read documentation, you have to use search engines, not always you can get information quickly, so you should have certain margin of safety to be sure that you will do everything as you have to.

Finally, of course good front-end developer should have good technical knowledge. And here I am talking more not about knowledge about certain frameworks, but about possibilities, that you can use during development. I mean, if for example I am working with button component, and my aim is to make it look pretty, I not always should remember all CSS properties, but I must remember about fundamental possibilities to change button color, or changing its border, or padding, or something else.

That were skills, which in my opinion, make a good front-end developer.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Explain the difference between cookies, session storage, and local storage?

A

Cookies are small pieces with limited lifetime, can be sent to server through special HTTP headers. Both server and client can read and write cookies, and this is possible to make cookies accessible only from server side, which is useful for storing authorization tokens. Usually they are used to store small pieces of information about, for example, authorization session inside application, so this case they store access token, for example.

Session storage is special key-value string storage, used to store certain information during one session. Session storage is separate for each tab. Session ends when browser closes, or this exact browser tab closes, and then this data is deleted.

Local storage is like session storage, but it is common for whole domain, and it is not deleted after tab is closed. It is usually used to store cached data or user settings.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are data- attributes good for?

A

Data attributes are HTML attributes that are starting with data word. These attributes we can freely edit, because none of them are used in internal HTML mechanisms. We can use these attributes for different purposes. For example, we can save certain information about element inside these attributes. Then we can access it through JavaScript or apply CSS styles depending on the content. Also, as I know, Vue framework uses data attributes to apply scoped styles to component.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Describe the difference between <script>, <script async> and <script defer>.

A

Script is loaded synchronously, so browser stops document parsing until resource is loaded.
Script async works differently. When browser reaches it, it starts resource loading, but none of browser processes are paused, they go in parallel.
Script defer is like script async, but its loading starts only after page is loaded.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Why is it generally a good idea to position CSS <link>s between <head> </head> and JS <script>s just before </body>? Do you know any exceptions?

A

Because this case any resources, that we are loading using links, are loaded before page content render starts. This is important, because in case of styles this helps us avoid situation when page content is loaded, but unstyled.
Script is good to place before body closing tag because this case we start script execution after page content is rendered. For example, in case of frameworks, this makes us sure that all other elements on page already exist, all styles are loaded, and we can freely mount our application.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are empty elements in HTML ?

A

Empty elements are elements that don’t have any content between open and close tags.

Example of these elements are image element, input, or link. All necessary information for them is provided inside element attributes, and they don’t have children nodes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is CSS selector specificity and how does it work?

A

Specificity is a rule that determines, which of styles will be applied to element when you have few conflicting styles.

It works so, that CSS looks on what of existing styles selector is most specific and uses this style to override styles with less specific selectors.

Most specific selector is inline style. CSS will always use inline style instead of any other.

Specificity for other selectors depend on many factors, including selector type and selector rule length.

I don’t remember all details, but mechanism works that way, when selector by element id is most important, then goes selector by class, and finally, selector by element type.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Describe Floats and how they work.

A

Float property in css allows us to make some kind of merging of two elements.

Element with float property will be displayed same way as if it had display property value “block”, it will shrink to its content size, except of cases when you directly set up width of element, and all next elements on page will flow around this element.

For example, if we have an image with fixed size and then text element after this image, and then we set up image property float value to “right”, then image will align to right side of parent container, and text element content will be shown in empty space on left side of image and below it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Describe z-index and how stacking context is formed.

A

z-index is CSS property, which determines the priority of element on imaginary z-axis. In other words, elements with higher z-index will be drawn above elements with lower z-index.

Stacking context is context, that determines, which elements will be rendered below or above other elements on page.

Each element with z-index property creates stacking context. Inside this context, all children elements height on imaginary z-axis is determined by their own z-index property.

So, let’s imagine that we have certain root element, and then inside this element we have two other elements, lets name then A and B. If we set up A z-index to 10, and B z-index to 5, then A element will be drawn above B element. And if A element has children element, lets name it C, with z-index of 1, then anyway C element will be drawn above B element.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Describe BFC (Block Formatting Context) and how it works.

A

Block formatting context is a region where block elements positioning is handled and where floats interact with other elements.

Block formatting context is created for all float elements, also for elements with absolute or fixed position, for elements with display set to “inline-block”, “table-cell”, “flex” or “grid”, or for elements where CSS property overflow is different from “visible”.

When this can be important? For example, if we use floats. Let’s imagine that we have container without fixed width and height, inside what we have float element. This case, this element doesn’t create its own block formatting context, and this float will affect on elements outside of this container. Also, this exact element size will be 0 pixels, because float removed from default document flow.
But if we, for example, set display property of this container to flow-root, or set it overflow to hidden, or something else, what creates new block formatting context, then this container will act as separate block, its width and height will already big enough to fit float element inside them, and this float effect won’t spread out of this container.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What are the various clearing techniques and which is appropriate for what context?

A

There are few different techniques what I know.

First, we can add an empty element with CSS property clear set to “both” right after float elements. This case all elements after float won’t be affected.

Second case, you can put these float elements and elements, what must flow around them inside another container element, and make this container create its own block formatting context, so other elements after this container won’t be affected.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

How would you approach fixing browser-specific styling issues?

A

Emm… Okay, lets imagine that we have few browsers and in some of them our styles are not working well.

First, I would try to detect source of problem and understand what styles and why are not applied to elements. Then, in case if that is possible, I would try to replace styles, what have problems in certain browsers with styles giving same outlook but working everywhere.

After that, if problem is not fixed, I would try to use polyfills to make it work.

Finally, if none of these things works, I would write script what would detect browser version and apply additional styles for browsers, where common approach is not working.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

How do you serve your pages for feature-constrained browsers? What techniques/processes do you use?

A

Well, on my last job place we were using polyfills to make page look same even in old browsers.

But if to talk in common, then I know few techniques that we could use in these cases.

We could use progressive enhancement or graceful degradation strategy, to make our page work even in case if user browser does not support all features.

Then, as I said before, we can use polyfills to support newer functionality in older browsers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

Have you used or implemented media queries or mobile specific layouts/CSS?

A

Yes, I had. I used to work with mobile specific layouts both on my current job place and also while I was developing my CV website. In both these cases I used global Vue storages to store information about viewport size, and then depending on this information, I was adding or removing certain styles to Vue components elements. So, for example in my CV project, if viewport width is less that seven hundred eighty pixels, then I add mobile class for root element, and then depending on CSS selectors, final style of certain elements is changing.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

What are some of the “gotchas” for writing efficient CSS?

A

First, this is good practice to use simpler CSS selectors to improve performance.

Second, this is necessary to avoid use of “!important” everywhere where this is possible, because it makes style management harder.

Third, your class names should be understandable and tell developer what they are doing.

Finally, this is good practice to maximally reduce use of inline styles inside project, because this also makes project harder to support.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

What are the advantages/disadvantages of using CSS preprocessors? Describe what you like and dislike about the CSS preprocessors you have used.

A

Good sides of preprocessors like “SASS” or ‘LESS” are variables, like in programming languages, higher agility, mixins, styles nesting and more complex mathematical operations.

Bad sides are need to learn new syntax when working with them and necessity to use additional build instruments.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

Explain how a browser determines what elements match a CSS selector.

A

Okay… First, browser is parsing CSS file, to understand the structure of styles and rules, following which these styles are applied to elements on page.

Then, browser goes through DOM tree to understand, which elements match CSS selectors.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

Describe pseudo-elements and discuss what they are used for.

A

Pseudo-elements are special CSS feature, that allows to modify part of element content through CSS rules, without need in additional HTML.

For example, using pseudo-elements we can separately edit first line or first letter of text inside element, or apply styles for text, selected by user, or add some content after or before element.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

Explain your understanding of the box model and how you would tell the browser in CSS to render your layout in different box models.

A

Box model is a main principle of elements layout in CSS. In this model, each element is a rectangle, or box, what consist of few components, like content, padding, margin, and border.

We can control used box model using box-sizing property. By default, it is content-box, what mean that element paddings and borders will be added outside of element block, and the element block in that case is element content block.

In case of border-box, all paddings and borders will be added inside element block, so in this case if we add borders or padding for element with fixed sizes, then they will take their space by reducing content box size.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

What does * { box-sizing: border-box; } do? What are its advantages?

A

This CSS selector makes browser change box model to border-box for all elements. This tells browser that for all these elements, their sizes should include not only their content, but also paddings and borders.

Advantages of this are next:

This makes manipulations with elements a bit easier, because when you change element width or height, then you can be sure that this element will be that size, and no additional space because of padding or borders will be used.
Also, when you change paddings or borders, you can be sure that layout won’t break.
Element sizes are always same, because adding or removing element borders does not affect on external element sizes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

What is the CSS display property and can you give a few examples of its use?

A

Display property defines how element is displayed on page.

Default value is block. Block element takes whole possible width on its row.

If we set its value to none, then element won’t be shown on page at all.

And with value set to flex, then element become a flexbox.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

What’s the difference between a relative, fixed, absolute and statically positioned element?

A

Static positioning means that element will be positioned following regular elements flow, and won’t be affected by positioning props like top, left, right or bottom.

In case of relative positioning element follows default positioning rules as static element, but its position can be adjusted using top, left, right or bottom props.

Element with absolute positioning is removed from regular document flow and will be positioned depending on position of nearest parent non-static element. This can be element with relative, absolute or fixed positioning. Absolutely positioned element can be adjusted using top, left, right or bottom props.

Elements with fixed positioning work same as absolutely positioned elements, but their imaginary parent, depending on which they are positioned, is viewport.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

Can you explain the difference between coding a web site to be responsive versus using a mobile-first strategy?

A

In case of responsive design we are developing website that way, when it will automatically adapt for different screen sizes and devices. This case we have one version of website, what is aimed to work well on all devices.

Mobile-first design mean, that our main aim is to make website look well on mobile devices. Mobile devices have less resources that computers, so we adjust its design to make website quick and minimalistic.
Then, after version for mobile devices is finished, we use different mechanisms to adjust it for other devices too.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q

Is there any reason you’d want to use translate() instead of absolute positioning, or vice-versa? And why?

A

I would use translate if I needed to create a CSS animation, because this way element remains in document flow, and keeps its space inside document. For example, if I had list of items, and I needed to move element a bit right when cursor hovered on it, then I would use translate property, because that is easier than move element using absolute positioning, because I need to keep its place in document flow.

From the other side, if to talk about case when I would prefer to use absolute positioning, then, this is probably the case, when I want to add some elements on page, which will be accessible by screenreaders, but not visible to user. So, I could just make element absolutely positioned, and add to id so big offset, that this element would move outside of screen borders. This case element would anyway remain in dom tree and accessible by screenreaders, but not be visible for regular user.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
35
Q

Can you explain the difference between px, em and rem as they relate to font sizing?

A

Size in px will be strictly that big in pixels, as its value.

Element with size in em will depend on font size of its parent element. So, 1em mean same size, as its parent font-size, and 2 em mean twice as much as its parent font size.

Element with size in rem works like em, but will depend on root element font size.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
36
Q

Can you give an example of a pseudo class? Can you provide an example use case for a pseudo class?

A

The simplest example of pseudo class is hover. Selector with hover pseudo class will match when cursor is over this element.

For example, we can create our custom link style, so we can use hover selector to make it change its background color to another when it is hovered.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
37
Q

What is the difference between a block level element and an inline element. Can you provide examples of each type of element?

A

Block element takes all available horizontal space inside his parental container and located on separate row. You can edit element width and height, and also add any padding and margin you want. Simplest examples of block element is div or p.

Inline element doesn’t create a line break, and take only space, necessary for showing their content. You can’t edit their width and height because it depends on their content, and you also can’t edit vertical margin and padding. Examples of inline elements are span and strong.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
38
Q

What is the difference between CSS Grid and Flexbox? When would you use one over the other?

A

CSS grid is a complex bidimensional layout system, which allow to create grids with multiple rows and columns. Its purpose is to control elements positioning inside this grid, including cells merging and control over sizes and proportions of rows and columns.

Flexbox is monodirectional layout system, where you can control elements positioning inside container in horizontal or vertical direction.
The aim of flexbox is to control how elements and free space between them are distributed inside the container.
Flexbox is better to use when you just need to align elements inside one row or column.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
39
Q

Explain event delegation.

A

Event delegation is a programming pattern, when we handle events on parent element instead of handling it on its children’s elements. There is sense to use it if we have many children elements which should do almost same action when you interact with them.
For example, we have page what consist of two sections. In the upper section there is a non-editable text area, and in bottom section there is a list of book names, and when we click on this list item, we need to open this book description in section above.
Instead of adding separate click event handler for each of these items, we could add data attribute for each of these elements, which will contain this book description, and then add click event handler for list element.
Then, when you click on any list item, this handler update text area content to clicked element data attribute value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
40
Q

Explain how this works in JavaScript. Can you give an example of one of the ways that working with this has changed in ES6?

A

“this” keyword is used to refer to context, where code is executed. The context is usually an object, where is located called function, where we use “this”.

In ES6 was added arrow function. This is function which does not create a new context, and uses context of environment, where they were created.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
41
Q

Explain how prototypal inheritance works.

A

An object in JavaScript can have internal reference for another object, which is called a prototype. It is some analogue for base class. If method not found in object itself, then JavaScript will search for them inside prototype, or prototypes of lower level.

When you create a class, which inherits some another class, then you will have all base class methods accessible from prototype.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
42
Q

What’s the difference between a variable that is: null, undefined or undeclared? How would you go about checking for any of these states?

A

Null mean, that variable has no value. Undefined mean same, but the difference is, that null is set by purpose, while undefined will be received when variable or property was not initialized. Undefined is some kind of soft error value, and you should not use it instead of null.
Undeclared variable is a variable that was not declared using const, let or var at all.

About how to check this.
For null we can just use triple equality operator.
For undefined variable we can use typeof operator or triple equality operator.
For undeclared variable we should use typeof operator.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
43
Q

What is a closure, and how/why would you use one?

A

Closure is a function in JavaScript, which remembers its lexical environment variables when it was created, and then can access them, even after program execution thread has exited this lexical environment scope.

I would use a closure in case if I needed to create a callback, for example when I load something from server using special function and want to do some actions when server will return result.

I would also use it in case if I needed to create few separate counters. By counter I mean a function, which has a counter variable in its outer scope, and during execution it increments this counter variable and then returns its current value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
44
Q

What language constructions do you use for iterating over object properties and array items?

A

Usually when I need to iterate over object properties, I use for…in loop, to iterate over its keys and then inside each cycle get object key value. But this is also possible to use Object.keys function to get array of object keys and then iterate it using forEach, map, or reduce function.

For iterating over array items usually I use for…of loop, map or reduce.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
45
Q

What’s a typical use case for anonymous functions?

A

Usually use cases are next:
First, callbacks, when we need to do some actions after our async function has finished.
Second, immediately invoked function expressions.
Last event handlers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
46
Q

Explain the difference between: function Person(){}, var person = Person(), and var person = new Person()?

A

In first case we create a function named Person, in second case we create a variable and set its value to result of Person function execution, and in third case we create a variable and set its value to new instance of class Person.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
47
Q

Explain the differences on the usage of foo between function foo() {} and var foo = function() {}

A

In first case we create function with name foo. We can access this function from any other place of our code in same scope, even before its declaration.

In second case we create a variable foo with its value set to anonymous function. In our code we can access this variable only after its declaration place.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
48
Q

Can you explain what Function.call and Function.apply do? What’s the notable difference between the two?

A

Both these functions do almost same thing. They call function passed as first argument. But call receives any number of arguments after function itself, and all these arguments will be used as function parameters, while apply receives array of arguments as second parameter.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
49
Q

Explain Function.prototype.bind.

A

Using bind we can force our function to use another this scope by passing it as first argument, and use certain input arguments, passed as all next arguments.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
50
Q

Можете ли вы описать основное различие между циклом forEach и циклом .map()? И в каких случаях каждый из них используется?

A

Map iterates over all elements in array and construct new array of values, returned from callback function for all items. forEach just iterates over all elements in the array, and doesn’t create new array.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
51
Q

Explain “hoisting”.

A

Hoisting in JavaScript is a mechanism, that moves declarations of all functions and all variables declared using var into top of their scope before code execution.

This feature makes it possible to use function even before their declaration in code, which sometimes can make code writing easier.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
52
Q

Describe event bubbling.

A

When any event is fired on JS element, this event propagation goes up in elements hierarchy. I mean, this event is also fired on its parent, then on its grandparent etcetera. Through this mechanism this is possible to handle events on multiple children elements using one handler assigned to parent element, with no need to add new handlers for children elements when you add them.

But, from the other side, event bubbling can cause unexpected effects, for example, in case when we click on element, which is placed out of its parent box using fixed position, we still will get click event fired for parent element, even if children element is outside of its box.
So this is usually a good practice to stop event propagation in cases when this is not necessary.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
53
Q

Describe event capturing.

A

Event capturing is event propagation mechanism, which is realized in some browsers, which is opposite to event bubbling. During the event capturing our event is first fired on root element, then on its children element, which is one of target element parents, and then it goes in same cycle until reaches target element.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
54
Q

What is the difference between == and ===?

A

Double equality operator is a non-strict comparison. When comparing two values, it first tries to turn them into values of same type, and only after this comparison is executed. So, if we have string with number 1, and number with value 1, double equality operator will show them as equal.

Triple equality operator is a strict comparison. It returns true only if type and value of two operands are same.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
55
Q

What is strict mode? What are some of the advantages/disadvantages of using it?

A

Strict mode appeared as a result of need of changes in JavaScript.

By default, language has been developing with backward compatibility. So, new functionality was appearing, but old functionality was not ever removed.
But this changed in ES5, where some already existing things were changed or deleted.
In order to keep compatibility, it does not use them by default. In order to use modern variant of language, this is necessary to manually add “use strict” into script file.

For example, strict mode forbids setting values for undeclared variables, or use of some outdated or unsafe functions, for example “with”. Also, I heard that in some cases using strict mode can improve performance, but I can’t give any examples.

About disadvantages… Strict mode is not supported in old browsers, so it can create problems and unexpected behavior. Also using strict mode can change behavior of code of other libraries, or your own code, which was created following requirements of non-strict mode.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
56
Q

What are some of the advantages/disadvantages of writing JavaScript code in a language that compiles to JavaScript?

A

At first, this makes it possible to make code more reliable.
For example, you can use newest language constructions and functions, but they will be turned in safe and fully supported code, compatible with older versions of JavaScript.
Also, of course, compilers can optimize your code, improving its performance, and minify it, to reduce code file size, and analyze it for possible mistakes made by programmer.
Finally, some languages, which are compiled to JavaScript, can offer absolutely unique features, for example like types and interfaces in TypeScript.

Disadvantages. First of all, of course you need additional step in your project assembly, this is compiler. This additional step not only takes time to do its job. Also compiler is a program, written by other people, and can contain bugs and errors.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
57
Q

What tools and techniques do you use for debugging JavaScript code?

A

For me in most cases enough just few things.

First of all, this is IDE and project build tools, like vite. They can check code on early stage and tell you if you made a mistake somewhere.

Second, is Google Chrome developer tools. This is console, overview of DOM tree and network overview.

I also had experience of using special plugins, for simpler interaction with frameworks. For example, I used plugin for Chrome which allows to see what Vue applications exist on current page, and see all their internals, like current state, computed values, methods, and more.

58
Q

Explain the difference between synchronous and asynchronous functions.

A

Synchronous functions are executed in series and block code execution until they finish their work, and result is returned directly after function has finished working.

And if we have too many synchronous functions in call stack, this can lead to interface freezing.

Asynchronous functions are functions what were made to handle things, what we usually handle with callbacks, in more convenient way. Asynchronous function is a function, which awaits for certain event, and only after this event happened it calls its handler functions.
This asynchronous functions are stored in a queue, and after call stack is empty, browser checks if we have enough time before next frame should be drawn. By default, new frame should be rendered every 16 milliseconds. So, if we have enough time, it executes asynchronous function and all functions from microtasks queue, like then or catch. And then it repeats the process until we have no free time.

59
Q

What is event loop? What is the difference between call stack and task queue?

A

Event loop is a mechanism which makes it possible to use asynchronous code in JavaScript.
There are two main parts of event loop, this is call stack and task queue. All synchronous code goes to call stack, and executed synchronously. All asynchronous code goes to task queue, and executed when there are no tasks in call stack. Browser checks if we have enough time before next frame should be drawn. By default, new frame should be rendered every 16 milliseconds. So, if we have enough time, it executes asynchronous function and all functions from microtasks queue, like then or catch. And then it repeats the process until we have no free time.

60
Q

Can you offer a use case for the new arrow => function syntax? How does this new syntax differ from other functions?

A

Use cases… First, when we create a function, what should be instantly invoked right after its creation. Using arrow functions is more compact. Their compactness is also useful when we iterate over the array using map and need to do some simple actions with its elements, because this case we can write it inline.

Also arrow functions are useful for making callbacks, because they don’t create their own context. Finally, we can’t use arguments keyword in arrow function to see all the arguments passed into function on call.

61
Q

What advantage is there for using the arrow syntax for a method in a constructor?

A

Advantage is that this case function doesn’t create its own context, and uses its environment context, so it can access this context variables later.

62
Q

What is the definition of a higher-order function?

A

Higher order function is a function which returns another function as result or takes any other function as its parameter.

63
Q

Can you give an example of a curry function and why this syntax offers an advantage?

A

Curry function is a function of higher order, which takes arguments one by one and on each step except of last, returns another function.

Why this syntax offers an advantage? Well, probably is some cases we could need to have intermediate function with already partially applied arguments, and then we can use it in code later, without need to put again and again same parameters.

64
Q

What are the benefits of using spread syntax and how is it different from rest syntax?

A

Using spread operator we can easily surface clone array, or make a new array from few separate arrays. We also can use this operator to provide array elements as parameters for function with unlimited parameters number.

Using rest operator we can accumulate arguments into array in function or destructive variable initialization.

The difference is in their functionality. Spread operator is used to make arguments list from array items, while rest is used to accumulate arguments into array.

65
Q

How can you share code between files?

A

First of all, I can use JavaScript modules. This case I can export and import anything I need in convenient form.

Second way is to use global variables. This case we create a variable with global scope and then use it to share data between different parts of our application. But this is not good practice, because this is hard to control and that makes code complicated.

66
Q

Why you might want to create static class members?

A

In few cases. First case, when I need to have some data common for all class members. This case I can use static variables, to access this data from class instances.

That is also useful to create static class members in case when we need to create a singletone in our application. This can be class working with database, or with api, or with something else, where we must have only instance of class, interacting with all these things.

Third, we can use static functions to create a helper class, providing some utilitary functionality. These functions don’t need any class instance variables to work. For example, this can be mathematical functions or API functions.

67
Q

What is a promise? Where and how would you use promise? Why do we need promise?

A

Promise is a special object which represents asynchronous function execution result. Promise can have three states, first is “pending”, while our asynchronous function not yet finished its work and not returned any result, “rejected” in case when an error was thrown inside function, and “fulfilled”, when our function has successfully finished its work.

We use promises everywhere where we work with asynchronous functions and expect to get any result from it or handle possible errors. This can be API calls, timeouts, or other asynchronous things.

68
Q

Discuss how you might use Object Oriented Programming principles when coding with JavaScript.

A

Okay… So, JavaScript is functional language, basically, but it also provides some things that can help us to use it as object-oriented language. In some places it works better, is some worse.

In order to work with it like with object-oriented language we can do few things.
First, of course, is to use classes. JS classes are not real classes, this is just more convenient way to construct a JavaScript object with predefined properties and methods, but anyway you can do some object-oriented things with them. For example, classes in JavaScript support inheritance. You can new class based on another class, and then this new class will inherit all properties and methods from base class.

Second thing is encapsulation. You don’t have private properties in JS same way as you can have them in C#, for example, but anyway, you can use closures and modules to create variables with very limited scope, and make them accessible only from certain functions.

Finally, can use polymorphism in JS because you can override methods and variables in subclasses.

69
Q

Что такое область видимости?

A

Область видимости – это набор правил, по которому будет определяться, можно ли взаимодействовать с той или иной переменной или нет.

70
Q

Что такое полиморфизм?

A

Полиморфизм – способность объекта реализовывать принципиально одинаковый функционал разными способами.

Примером этого может быть интерфейс, определяющий функцию, и различная реализация этой функции в классах, реализующих данный интерфейс.

Polymorphism is the ability of an object to implement fundamentally the same functionality in different ways.

An example of this would be an interface that defines a function, and a different implementation of that function in classes that implement that interface.

71
Q

Что такое KISS?

A

KISS is principle, that says, that code must be kept as simple and understandable, as possible.

72
Q

Что такое SOLID?

A

SOLID is set of rules that is recommended to follow to make code development easier.

There are five rules.
First rule is „Single responsibility“. This mean, that one class should be focused on making actions in only one aspect of application. For example, if we have a shop and for this shop we have class Product, that by idea describes one type of commodities we are selling, then this class Product can have properties that describe this product, but for example must not have any method that will directly implement saving information about this product into the database, because that is absolutely another functionality. To implement this functionality, we should create another class, what will be focused on interaction between any kind of product we have and database.

Second is “Open-Closed principle”. This mean that any class we have should be open for extension, but closed for modification. If to talk simply, we must provide possibilities to add new functionality into class without touching existing code. This is possible to do using abstract classes and interfaces.

For example, we have a function what takes array of different geometrical figures and must draw it. Each figure has its top left point coordinates, and figure-specific information, for example, for square that can be length of its side, and for triangle length of all its three sides, and for other figures something else.
There are two ways of doing this. First way, we could create separate classes for each of shapes, each with its own specific information and methods. And then, in function, we check what class we interacting with and depending on this, we draw it, calling class-specific methods or functions.

Other way, where we follow open-closed principle. We create certain interface for abstract shape, and in this interface we define only top left point and method Draw(). After that, we create all other shapes classes using that interface. During program execution, we handle each shape as abstract instance of this interface implementing object, and just call function Draw().
This case we are free to add new shapes classes without need to modify existing code of function.

Third is “Liskov Substitution principle”. It says, that any child class of base class should extend functionality, but never narrow it.

For example, we have a class that describes Rectangle. One moment, we want to add class, that is describing Square. The problem here is, that while Rectangle has width and height and these values can be different, Square width and height are always same. And if we inherit class Square from Rectangle and then override it that way, that when we set width, it also modifies height, and vice versa, then we violated this principle. This is bad, because this case any function or method that interacts with Rectangle, and during program execution can get instance of Square class as instance of Rectangle class, it will suffer from problems related to this width and height issues.

Fourth is interface separation principle. This principle says us, that this is better to have a big number of small and specific interfaces, that small number of big interfaces.
This is important because at first, helps us to develop program in cases, when there could be classes with similar functionality, but what are different in some moments.

For example, imagine we have a class describing a calculator, and we have one big interface for this calculator. This calculator has huge functionality and allows us to use many complex mathematical functions. One moment, we decide, that we need to create another calculator class, but this case we need just simplest functionality, like possibility to add, subtract, multiply and divide numbers. And there is the problem, because this case if we use same interface as for previous complex calculator class, then we have to implement many methods that will never be used. This is not good.
So, instead of making one big interface, we make a lot of small interfaces. For example, one interface describes method that sums up two numbers, second describes multiplying and so on. This case we can just implement few small interfaces for simple calculator class.

Last principle is “Dependency inversion principle”

This principle says that classes should depend on interfaces or abstract classes instead of exact classes or functions.

73
Q

Что такое миксин

A

Mixin is a piece of functionality or data that we directly inject into something.

For example, if we talk about CSS, then in CSS preprocessor SCSS mixin is feature, that allows us to define set of CSS styles somewhere once, and then in other classes definition just import this mixin instead of manually writing all same rules again.

If we talk about Vue, then mixin is like part of Vue component, that we add to our component. This injection can contain new data, new computed values, new methods, new action to do on component lifecycle hooks.

74
Q

What design patterns do you know?

A

Builder. This pattern is useful when we want to have a convenient and understandable way to create a class instance with certain set of characteristics.

There are three ways we can go.

First way is to follow telescopic constructor pattern. This case we have a very complicated constructor with many optional parameters on input, or multiple overloads of this constructor with different parameters on input. The problem this case is that we have to provide big number of arguments, and this makes code writing and reading difficult.

Second way is so named JavaBeans pattern. This case we use constructor with no parameters to create a class instance, and then initialize all required fields of object by calling corresponding setters right after class instance creation. This pattern is solving readability issues, but is not so reliable, because you always can forget to initialize some of object fields. Also, this approach makes it not possible to make objects of this class immutable.

Finally, builder pattern. This way we create else another class, which we use in first class constructor. In builder class, we have all these fields, both optional and required, and getters and setters for each of them. We set up all builder class fields to match needed configuration, and then provide it as only argument of first class constructor.
This case we have all benefits, what have telescopic constructor and JavaBeans patterns. I mean, from one side, this is easy to read and edit, and we can initialize fields in any order, as in JavaBeans pattern, but we don’t lose possibility to make our final class instance immutable, or require some input parameters to be provided, like we have in telescopic constructor pattern.

Next pattern in Singletone. The idea of the pattern is to have only one instance of certain class in our application. This can be static class which we use to call API, or database, or just class storing our application settings.

Another pattern is event delegation. …

Finally, last pattern I can remember is decorator. With decorator pattern, we wrap an object or function with another object or function in order to modify its behavior without changing class or class instance. The simplest example of this pattern are function debouncing or throttling in JavaScript. For example, we have a function, which logs certain text into console, but we don’t want it to be called too often. So, we create another function, which takes our function as input parameter, and calls it only if certain time period passed from previous function call. In case of throttling, it also calls our function in the end of debouncing period, if it was called during it.

75
Q

What is CI/CD?

A

CI/CD means continuous integration and continuous delivery. The idea is to have an automated pipeline which will analyze and test code after developers made changes, and then deploy it into environment, where application is accessible by developers, or, if that were fully tested and approved features, by final users.

The aim of CI/CD is to improve reliability of code development and deployment process and automatize some things which other way would have to be made by developers manually.

Usually typical CI/CD pipeline consist of next steps:
First, detect changes in version control system, and build the project.
Then, move final code into test environment, where is possible to run it, and turn on application and related things, like databases, API endpoints, and others.
After that, go through the application and test it for bugs.
If everything is okay, then deploy an application, else, stop the pipeline and notify developers about it.

76
Q

What for we use events in JavaScript?

A

Okay…
I think, the main reason is that this is reliable and convenient way to do something when certain action was made. Right now, it works that way, that when you click on button, for example, browser creates an event object, and then if you assigned previously functions, which are handling this event, then after current code in call stack will be executed, browser will call your functions – handlers, with this event object as parameter. From event object we can take information about event and its environment, like event source, for example. And then inside this handler function we can do something with this information.

But let’s imagine for a moment, that we by some reason decided to get rid of this system, and just call certain function when certain event should be fired. So, when you click on the button, then it stops currently running program, and runs this handler function. Of course, this is not best way, because first of all, that would be not possible to assign more than one event handler for an event, and also would pause our synchronous code execution.

And if to go even deeper, lets imagine that we decided to completely get rid of events. So, this case in order to execute certain actions when button is pressed, we would need to manually check this button state from our code, and this creates a lot of problems. For example, we would be always afraid of situation, when button click was not detected because during this time period, we were not checking this button state, but executing any other code.

So that is the reason, why we use events. This makes it easier to handle things that happen to the user interface.

77
Q

MVC, MVP, MVVM

A

MVC – Model-View-Controller
MVP – Model-View-Presenter
MVVM – Model-View-View-Model

In MVC we have three parts of our application. This is model, view and controller.
The model is a business logic layer of application, or in other worlds, layer, responsible for manipulations with data.
View is an interface layer, responsible for showing data to user.
And controller is a layer between them, responsible for reliable communication between other two layers. So, for example, when user presses the button on View layer, it is sending request for Controller layer to return some data from Model. Controller Is checking if everything is okay with request and if yes, then returns requested data.
The benefit from this organization of code is that our Model, View, and Controller are mostly separated from each other, and in MVC application modification of each of these layers can be made independently.

78
Q

What is DNS and what it needed for?

A

DNS or Domain Name System, is a system used in Internet to transform human-readable domain names, like youtube.com, into IP addresses, which are used by computers for identification and interaction.

79
Q

What is clean function?

A

Clean function is a function, which has two properties.

First of all, it does not have any side effects. So, all changes, what it can do, it makes inside its internal scope.

Second moment is that in case of clean function each time we provide same data on input, we get absolutely same output.

Clean functions are easier to test and support, and also in case of clear function we can use caching decorator, to make it work faster in some cases.

80
Q

What is callback hell?

A

Callback hell is a situation, where we have nested callbacks. This code is hard to read, and this is hard to understand what is going on inside code and what and when will be executed.
All this makes interaction with code a bit painful, so this is a good practice to avoid nested callbacks, through separating the code into few smaller functions, and using promises instead of nested callbacks.

81
Q

What is the difference between var, let and const?

A

The first difference is scope and accessibility. Var is affected by hoisting, and it is accessible everywhere inside its parent scope. By parent scope I mean global scope, or scope of the function, where variable is declared using keyword var. Also, var can be redeclared few times.

Let and const, otherwise, are accessible only after their declaration, and can’t be redeclared. Also there is difference in case of const use. When we use const, first of all, we must give it value directly when it is initialized. So, if in case of var and let you can declare variable first, and assign value to it in code below, and before that moment variable value just will be undefined, in case of const this is necessary to have variable value assigned right in place of declaration. Also, const variable assigned value can’t be changed. So, if for example in case of let you can initialize it with value of 1 when you declare it, and later change its value to 2, in case of const you won’t be able to do this.

Finally, the other big difference between var and const and let, is that const and let scope depend not only on function where they were declared, but also on any other construction. So, if you have a code, where you declare variable using let, and then you have if block, and inside of this if block you declare variable with same name, then both these variables will be two separate variables.

82
Q

What is scope?

A

Scope is a region of a program, where it exists and can be recognized, and outside of what it can’t be recognized and used. There are different types of scopes in JavaScript, which are global scope, functional scope and block scope

83
Q

What is shadowing?

A

Shadowing is a mechanism, which allows us to have multiple variables with same name inside same scope. The idea of shadowing is that variable on lower level of scope overrides variable on higher level of scope. By override, I mean, that when we are using this variable name, we will interact only with variable on lower level.

As example of shadowing, let’s imagine next situation. We have a variable named “a” and declared using let on first line of our function. Then, a bit below, be have if condition block, and inside this block we have another variable named “a” declared. So, outer scope “a” variable will be shadowed by nested block scope “a” variable. And if we log variable a value inside this if block, we will get value of “a” variable, what was declared inside this block.

84
Q

What is First-class function?

A

First class function is a function what can be threated as any other variable. For example, function can be passed as argument to other functions, can be returned as function result, or can be assigned as variable value.

85
Q

What is lexical scope?

A

Lexical Scoping defines how variable names are resolved in nested functions: inner functions contain the scope of parent functions even if the parent function has returned.

86
Q

What “this” keyword refers to?

A

“This” keyword refers to the nearest parent object of function where this keyword was used.
For example, if we use this keyword outside of any function, in global scope in browser, we will get window object. If we use this keyword inside a function, which is part of class object, then we will get this class instance using this keyword. If we call a function using new keyword, then this will refer to new object instance, created for this function.

87
Q

How to optimize Vue application?

A

First of all, if we would be talking about Vue 2, I would say, that we can optimize our application through turning all our stateless components into functional components, which would improve the performance. But in Vue 3, functional components does not work much faster than regular components, so this does not make a big sense.

Then, we could check our application for cases, when we toggle component visibility using v-if directive. If these components what we toggle are quite heavy and take a lot of time to mount, and we by some reason need to toggle their visibility relatively often, then would be better to get rid of v-if directive and use v-show instead.

Third, in order to reduce time it takes for user device to load code from server, we could chunkify our project final assets. For example, in tools like Vite we can achieve this through components lazy loading using import function, or through editing build config.

Finally, in case if we have any place in our application where we perform big synchronous operation, we could check if we can split this operation into multiple asynchronous operations. This case we will have no interface freezes during runtime.

88
Q

What are slots in Vue?

A

Slots in vue are another way how we can provide certain information form parent component to children component. For example, we have parent component A, and its child component B. Through slot we can provide other Vue components or HTML elements, and these items will be used inside component B template in place where we have this slot what we are working with.

Slots in Vue can have names, or be nameless. In case if we don’t provide any specific name for slot, its default slot, and it will receive all children of this B component, what we will have between opening and closing tag of B component. If we provide name, we can access this specific slot using template element and using v-slot directive on it.

Also we can provide certain information from component B into component A when we use slot. We can set some properties inside component B, and then we will be able to access these properties inside template element what we use for this exact slot inside component A.

Also, we can have some fallback content for slots. This fallback content we put between opening and closing tag of component slot, and it will be used in case if we did not provide any value for this slot when using component.

89
Q

What are the disadvantages of Vue 3 compared to Vue 2 and other frameworks?

A

Well, if to compare Vue 3 to Vue 2, then the most important disadvantage is that Vue 3 is not always backward compatible with Vue 2. Framework reactivity system was reworked, and also some other features from Vue 2 were removed. For example, it was possible to use certain Vue 2 component as event bus, and using this.$on and this.$emit handle events across the application. Now, in Vue 3, you have to use third party libraries for same functionality.

Next problem is that Vue 3 is not still so wide used, and some third party libraries can support Vue 2, but not Vue 3.

Well, so, talking about these third party tools and libraries, about this ecosystem, I can say that third disadvantage of Vue 3 is that its ecosystem is smaller than for example, ecosystem of React.

Finally, last disadvantage what I can remember, is that all component parts are in one same file. I mean, in single Vue file you have component template, component internal scripts and logic, and also styles. This is good if component is small and compact, but it can become a problem is component is quite big and complicated.

90
Q

What are advantages of Vue comparing to other frameworks?

A

First of all, simplicity. This is easier for you to start with Vue than with other frameworks like React, for example. Everything is quite intuitive, you have less problems with its internal mechanisms.

Also, as I know, Vue provides modularity. So, you can easily split your final build assets into smaller pieces, individual for each separate component you have in your project, and then during runtime load only these pieces of code which are currently needed, instead of huge JavaScript file where all application code is stored.

Finally, I want to tell a couple of words about component file structure. In Vue, we have component template, script and styles all together in one file. From one side, this is good, because this is convenient for developer when you don’t need to switch between multiple files during development, but from other side, this quickly becomes a problem when your component is big, so you have to scroll a lot to get access to different parts of component.

91
Q

What is idea of Composition API in Vue?

A

Composition API allows you to split your component logic into separate pieces, named compositions. In each of these compositions you have your own separate logic and state, what this logic works with. These compositions can be reused in different components, reducing code duplication and increasing reusability.

Composition API makes components code more structured, allowing for more effective ways to organize complex logic and state management in components. This is especially important in big projects, where we need to have good scalability and support.

This approach, used in Composition API, solves two main problems which can have Options API.
First is situation, when we have one component, which incapsulates few logically separated tasks. This case we could export this logic into reusable Composition API modules.
Second problem is need in reusing same logic inside different component. Simplest example is sorting list of items. We can have one Composition API module which is aimed on solving this problem and use it in all places where we need to sort items

92
Q

What are Vue directives?

A

Vue directives are special attributes what start with “v”, and what you can use for adding special behavior for components.

For example, using v-bind directive you can bind certain component attribute value to JavaScript expression.
Using v-for you can repeat component multiple times.
Using v-if, v-else and v-else-if you can control component rendering depending on certain condition.
Using v-show you can control if element is visible or not.

You can create your own directives

93
Q

What is DOM tree?

A

DOM tree is a tree what browser builds from HTML template. DOM tree consist of nodes, where each node is an element, representing certain HTML tag. Elements can have different functionality and different events what they can fire.

94
Q

What is BOM?

A

BOM is Browser Object Model. This is set of JavaScript objects, which provide you methods to interact with browser and browser environment. For example, it provides screen object, which provides you information about display, or navigator object, which provides you information about user browser, or location, using that you can get current url or go to another url.

95
Q

How events in Vue work?

A

In Vue, each basic HTML element and each Vue component can fire events, which you can listen to. In case of Vue components you can create new events what can be fired from this certain component. Later, in parent component you can listen to this child component custom events. Each event has its own key, by what it is listened and fired, and also this is possible to provide additional data together with event.

In Vue 2 that was possible to programmatically add event listeners during runtime, so you could use certain Vue component instance as event bus for whole application. But in Vue 3, this feature was removed, so you still can fire events from the component, but this is not anymore possible to add event listeners during runtime, so if you were using event bus created like that in your application, then you would need to use third party libraries instead, when you migrate from Vue 2 to Vue 3.

96
Q

What is the difference between Vue slots and scoped slots?

A

The difference is next. Lets imagine a situation, that we have parent component A, and inside of it, child component B, for which slot we provide content inside component A template.
In case of regular Vue slot, we can build its content based only on data that we have in parent component.
But if we add some properties from component B data to slot element inside component B template, then we will can to access these properties from component A template, inside template element which we use to provide content for this certain slot.

97
Q

What are Vue filters?

A

Vue filters are functions, which you can apply to certain property or data value inside component template. To use filter, you should add vertical line after value you want to apply this filter to, and then write this filter function name

98
Q

How you can use v-for directive for rendering elements?

A

In v-for directive you can iterate over arrays using “in” keyword, and objects using “of” keyword. In case of in keyword you iterate over array elements, and can have access to this element value and index. In case of objects, you iterate over key-value pairs inside object, and have access to key, value, and index of current item inside object.

99
Q

How you can register Vue component inside another component?

A

You can register Vue component inside another component through importing it from file, and then adding this imported component into components object of your second component.
This case, you will be able to use this first component inside second component template without need to globally register it.

100
Q

How you can define styles in Vue?

A

In Vue we can define our styles in two ways.

First, we just create css file with styles and import it inside our component script.
This case these styles will have global scope.

Second, we can use <style> tag inside Vue component file, and put our styles there.
They sill will be global.</style>

Last way, is to add scoped attribute to Vue component file style tag, and in this case these styles will be local and will be applied only inside this component.

But in last case, there is anyway a chance that our parent component styles will flow into children components. This can happen, for example, in case if we have certain class, lets say named “container” in our parent element, and we have class with same name inside our children component, and inside our children component we use this class for most top element. This case styles from our parent component will be applied to our children component too. This happens, because Vue uses HTML data attributes to control slots scope. The problem is, that if you use any component inside another component, this parent component data property will be applied to children components most top elements.
So, when you are working with styles in Vue, you have to remember about this problem.

101
Q

What are functional components in Vue?

A

Functional components in Vue are simple stateless components, which are just simple rendering structure. Functional components in Vue have no internal state, no lifecycle hooks, almost nothing, but they can have access to their props and context. From context we have access to slots and attributes, provided to this component.

102
Q

What ways to add animation into Vue application do you know?

A

First of all, we can use inbuilt components Transition for individual elements and TransitionGroup for lists to add some animation when we add or remove list items.

Also, we can transitions and animations through assigning certain classes or styles to Vue components.

Finally, this is possible to use JavaScript to animate component. Last way gives us more agility, but can be quite slow comparing to previous variants.

103
Q

What are plugins in Vue?

A

Plugins in Vue are inbuilt way to extend whole application with new functionality. Plugins usually provide certain set of new components, directives or other things, which are accessible from any part of the application. For example, in our application we install things like Vuetify or storages like Vuex or Pinia as plugins.

104
Q

What are dynamic components in Vue?

A

Dynamic components are components, which are conditionally rendered depending on application state.

There are two ways how we can use dynamic components in Vue.
First way is just to use v-if, v-else-if and v-else directives to conditionally render one of components under these directives.
Second way is to use Vue component named “Component”, and provide desired component name into its “is” property. This case instead of this component will be rendered component, name of which we provided.

105
Q

What are asynchronous components in Vue?

A

Asynchronous components in Vue are components which we import using dynamic import function. To import any component asynchronously, we can use defineAsyncComponent function, where we have provide a callback which returns import with path to this component as first argument.

Asynchronous components in Vue have two important properties.
First of all, they allow you to have cyclical dependencies between your components.
Second important moment is that if you have component imported asynchronously, then build tools like Vite can put its output code into separate file, so this makes you application more optimized, because this case user won’t need to load code for components which are not used on page currently.

106
Q

What is global component registration in Vue?

A

Global components registration of component is way of registering Vue component that way when it is accessible from any part of application.

In order to register component globally, we can use component method of application instance. After that, we will be able to use this component from any part of our application.

107
Q

What is Dynamic Route Matching in Vue?

A

Dynamic route matching in Vue is a mechanism, which allows us to set up routes, certain parts of what can take variable values. To do this, on certain route segment can use colon and then provide this segment name. Then, when user will visit this segment, any value provided instead of dynamic segment will be accessible inside component under this segment name.

108
Q

What for do you need “key” attribute on Vue component?

A

Vue component key attribute is needed for optimization purposes in lists of component, created using v-for loops. So, using key attribute you specify unique identification marker, which Vue uses to track elements order, deletion and adding.

For example, you have simple component which is just div with random number inside. And this number is saved inside this component data. Also, you have array of items which are unique numbers and for each of this item you create component in list using v-for directive, and do it with no keys, Vue will try to minimize component changes. So, if you rotate this array, Vue won’t recognize that it should somehow move corresponding components under v-for directive, and you will see no changes inside list. But, if you provide key, where for key value you set this exact item value, Vue will also track the order of these elements, and move them when order of items has changed.

109
Q

What is requestAnimationFrame and what for we can use it?

A

requestAnimationFrame is a special function, which you can call to execute certain callback function right before next browser frame will be rendered.

We could use it for example for JavaScript animations. The simpliest example is that we have certain point inside container, and we want to move this point following complex curve, where we calculate current point position using function. So, this case we can use requestAnimationFrame and certain time delta, which passed since last frame render to adjust point position to new coordinates, calculated inside this function.

But now, you can have question, why can’t we do this using setTimeout or setInterval instead? And the answer is pretty simple – in this case our point new position calculation will be not synchronized with our framerate. So, if we have few points which with similar behavior inside this container, then their final animation time can be different, and this won’t look well.

110
Q

What is your experience of working with TypeScript? What are its advantages and disadvantages comparing to JavaScript? What do you prefer?

A

I used TypeScript in few projects, for example when I was working on my CV website or task planner. In first case project is based on Vue, in second – on React, but in both cases I was using TypeScript there.

So, what are advantages and disadvantages of TypeScript, comparing to JavaScript? First of all, TypeScript has unique feature, which we almost don’t have in JavaScript – types. So, with TypeScript, this is more obvious, what are you working with, when you are writing code. Also, this helps you to find some type errors on early stages, during compilation. So, if you for example have variable of number type and then you by some reason trying to assign a string to it, you will quickly understand that you are trying to do something in wrong way.

Also, we have another small advantage, is that TypeScript allow you to use newest JavaScript features, because your code anyway will go through compilation stage and could be compiled into older JavaScript standart code with saving the functionality.
But I would tell that this advantage is not very important, because modern project build tool like Vite, for example, allow you to recompile you JavaScript code into code of older version. So this is not TypeScript unique feature.

About disadvantages.

First of all, if you want to write code using TypeScript, you have to learn TypeScript. So this takes additional time to start.

Also, you need to write more code with TypeScript, to describe all these types and interfaces.

Finally, you need additional dependency in your project and additional project building stage. This takes additional time and can increase number of potential vulnerabilities.

111
Q

What are Proxy and what for you could practically use them?

A

Proxy is a special class in JavaScript, which allows us to wrap any other JavaScript item with it.

In proxy, we can have different middleware functions, called in different situations, which give us higher control over operations and side-effects.

We can use proxy for different purposes. For example, Vue uses proxies to add reactivity into application. We also can use proxies in React, for example, to create special state hooks, which return objects working like reactive objects in Vue, instead of using useState hooks. Finally, last example is that we can use getter middleware for object to return certain default value if requested property does not exist in object.

112
Q

What is TDD (Test Driven Development)?

A

Test Driven Development is a development, where when you want to add new functionality into your application, you write tests, covering this functionality, first, and only then write code for this functionality itself.

This approach makes your code more covered with tests, so it makes it more reliable. Also, when you are writing tests, you have time to think about, for example, what your function should return in what cases, and what are edge cases, etcetera, so this is easier to write man functionality after writing tests.

113
Q

How do you achieve clean architecture in your code?

A

There are few things what I can remember now that you can use to make code better.

First of all, responsibilities separating. So, your code should be divided into modules, and each of modules should be responsible only for certain narrow functionality.

Then, whole project structure must be predictable. So you need to have certain agreement, where you put different parts of code in your project.

After that, code should be clean. So, no five hundred lines methods, no senseless names, nothing like that. That should be easy to understand what your code is about, and easy to edit it.

Then, you should follow certain architectural patterns, like MVC or any other, so your project should be divided into separate layers, each of them doing only certain kind of tasks.

Finally, you should follow SOLID and KISS principles to make your code more understandable and reliable.

114
Q

What is reactivity in Vue?

A

Reactivity in Vue is a system, which allows dynamic reaction to changes in state.

In Vue 2 reactivity was achieved through getters and setters, but Vue 3 approach uses Proxy to make state reactive.

115
Q

Tell me everything about State Management pattern.

A

State Management pattern idea is to create separate globally accessible storage, which is a centralized endpoint for managing certain state.

This makes it possible to avoid certain antipatterns like props drilling, allows for more simple state management for certain data, and makes application more reliable, providing only limited number of ways to interact with storage.

For example, in storages like Vuex and Pinia we can’t change storage state directly. We can read it, but writing into storage is possible only from this storage actions or mutations functions.
This is more predictable approach, because we always know, where and how our state can be changed.

116
Q

What are styled components and is that possible to use them in Vue.js?

A

If I remember correctly, styled components are components, where we use CSS-in-JS approach to inject CSS style into certain templating tool to create new prestyled component, which we can use in Vue template. But I never worked with them, so I can’t tell you a lot.

117
Q

What is $nextTick in Vue?

A

$nextTick is a special function in Vue, which allows you to provide a callback, what will be executed after DOM tree will be updated.

This is important, because Vue updated DOM tree asynchronously, so if you changed component state and want to get access to updated DOM elements, then you need to use $nextTick to be sure that your code in callback will interact with updated DOM tree.

118
Q

What is virtual DOM and what for do we need it?

A

Virtual DOM is a simplified version of real DOM, which we use in Vue and some other frameworks in order to minify expensive operations with real DOM tree.
Virtual DOM is just a tree of JavaScript objects, which can be accessed at relatively low cost.

We use virtual DOM to compare old and new versions of virtual DOM, and then update DOM tree only in places where real changed happened.

Also, virtual DOM is easier to work with than with real DOM, because this case developer can not care about how certain browser or platform works with real DOM, so this is more reliable and predictable instrument.

119
Q

What are ways to create watchers in Vue?

A

If to talk globally, you can do this in two ways:

First – through modifying Vue component watch option. In this object, you can add new watcher through writing variable or prop value as key and assigning handler function as value.

Second way is to use watch or watchEffect functions inside component setup.
In first case you provide callback, which returns item you want to watch for as first argument, and second argument is handler function.
In second case watchEffect will automatically resolve all dependencies and call its callback every time when they are changed.

120
Q

How do you think, what for frameworks like Vue, React etcetera are needed? Why do they exist?

A

There are many reasons.

First of all, they provide much simplier way to solve frequent problems like variables value binding to certain elements properties, or events handling, or mounting and unmounting of components etcetera. With frameworks this is much easier to write code, because you can concentrate on what you want to do instead of how to do this.

Second moment, is that frameworks provide possibility to create building blocks like components, which are reusable and can encapsulate certain functionality inside.

Finally, they limit you in how you can solve this or another problem through restricting certain design solutions and adding strict patterns. On first look this can look as something bad, but really, this makes your code more predictable and makes it easier to write and support.

121
Q

What is big O notation?

A

Big O notation is a concept, which is used to measure resources consumptions increase rate when using different algorithms. This resource can be time, number of operations required to calculate result, or memory consumption.

Big O notation shows us, how much certain resource consumption changes, when we change input data in certain direction.

Right now I can remember few of Big O notation complexity types.
Complexity can be linear, or in other words, resource consumption increases in same rate as amount of data to process on input.
Also complexity can be logarithmic, linear-logarithmic, square or have another power, or can be factorial, constant or exponential.

122
Q

What are Symbols in JavaScript?

A

Symbols are special identifier, which can be used in object. Each symbol is unique, and we can’t have two symbols with same value.

Symbols can be used in objects, to add certain property to them, and that will be almost impossible to access this property from any other part of our program, which does not have access to this certain symbol.

As example of situation, when we can use symbols, is a case, when we want to write polyfill for call function method. So, how call works? We can provide this as first argument, and rest of the arguments will be received as array of arguments and applied to this function as regular list of arguments.

Do write polyfill, we can define new symbol inside polyfill call function, then add this function into this object using symbol as key, and then call it using these arguments.
After that we remove this key-value pair from object.

123
Q

What data types in JavaScript do you know?

A

Boolean, number, bigInt, string, object, null, undefined

124
Q

How does page rendering work?

A

Well, first of all, after page html is received from backend, browser parses it and creates DOM tree. If during parsing browser founds out, that additional external resources like styles or scripts are needed, it loads them.

After that, browser parses CSS files and builds CSS Object Model.

Next, browser goes through DOM tree to understand, which styles should be applied to what elements.

Then, browser calculates layout, and renders current frame, which is shown to user.

Last three steps are repeated on each next frame render.

125
Q

What are primitives?

A

Primives are types, which are provided by value.

126
Q

What ways to work with asynchronous code do you know?

A

First – through callbacks.
Second – through Promises.
Third – through async / await.
Fourth – through events, because events are asynchronous.
Finally, I would say, that we could use generators to handle asynchronous code.

127
Q

What WebWorkers are?

A

As I know, WebWorkers is a mechanism in browser, which allow to execute code in parallel in the background. WebWorkers execution threads are separated from each other and from main thread, where default JS code is executed, so they have no access to DOM tree or global objects like “window”.

Information sharing between main thread is possible using asynchronous messages.

128
Q

Why we can work with Primitives like with objects? Call their methods etc.

A

Because JavaScript provides certain object wrapper over primitives.

129
Q

What are tags and attributes in HTML?

A

Tags are key elements in HTML. They define the structure of elements tree and type of this tree nodes.

Attributes are some text additions for tags, and they provide additional information to tag, which can change its behavior.

130
Q

What is model in Vue, how it works in Vue 2 and Vue 3?

A

Model in Vue is bidirectionally bound property. In Vue 2 you could have only one model, which would work with one property, but in Vue 3 you can have multiple models on your component.

131
Q

What are teleports in Vue 3 and how they work? Where can we use them?

A

Teleports in Vue is a special new component, added in Vue 3, which allows you to move certain items into another place inside real DOM tree, regardless of where they were in Vue components tree.

132
Q

What are utility types in TypeScript?

A

Utility types are special types using what we can modify other types.

For example, using Omit we can get rid of certain properties in type, using Pick we can pick certain properties from type, using Required and Partial can control should properties be optional or not.

133
Q

What are enums in TypeScript?

A

Enums are special kind of objects in TypeScript. Enums are constant, their keys and values are set once, and can’t be changed. Enum values can be only numbers or strings.

134
Q

What is difference between different databases (MySQL, PostgreSQL, SQLITE)

A

At first, there are two main types of databases – relational and non-relational.

In first case we have our database consisting of bidimensional tables of rows and columns, where column represent certain piece of data, which every entry can have, and describes its type. Each row is separate entry, which stores certain set of information, defined by table columns.

In second case we have more agile struture, optimized for cetain specific data type and optimized for working with this data type. For example, this can be key-value relation, or set of graphs, or something else.

Well… If to talk about differences between relational databases, then there can be quite a lot of differences depending on database.
Depending on database, can differ data types, which can be stored inside its cells, or some other things like completeness of SQL language implementation, performance or extensibility.

For example, lets take a look on three most popular databases, which are SQLite, MySQL and PostgreSQL.

SQLite is a simple file-oriented database. It provides most basic functionality and implements database storage as single file on hard drive. It has some limitations, comparing to full SQL standarts, and also has quite limited amount of data types it can use. But, from another side, its quite compact and has quite good portability. SQLite database is perfect fit for small local storages, which should not be accessible from multiple places.

MySQL is more advanced and most popular server-side database. It provides much wider column types set, good scalability and good safety out of the box, but still does not implement all SQL operations, and has some issues with read-write operations, happening at same time.

PostreSQL is most advanced relational database, completely implementing all SQL features and having good concurrently executed tasks support, but has lower performance and higher complexity, comparing to other instruments.

135
Q

What is difference between monolith and microservices architecture?

A

The main difference is that in case of monolith, all our solution parts are stored together, in tight integration, and in case of microservices, our solution is separated into few independent modules, responsible for certain narrow functionality, and communicating with each other using Internet.

About advantages and disadvantages of each approach.

Monolith is good because it all project parts and together in one repository, and if you need to connect one part of application with another, you can do it easily and quickly.
Monorepository is bad from that side, because if you need to access functionality of one application part from another application part, stored inside another monorepository, then you have to do this through HTTP requests or somehow else through the Internet, and this is much slower and not so convenient.

Second moment, is scalability. This is much easier and much faster to expand module with narrow functionality, than expanding monolith.

Also, this is onboarding on microservices projects is much faster and easier, comparing to monoliths, because this case new developer need to learn less new information.

Finally, I would say, that this can be a problem if microservices are not completely agreed about format of their endpoints and functionality. There is needed more interaction between different teams to make everything work.
Same time, in monolith, you always can see what works in what way and how these parts are connected to each other.

136
Q

How do you rate your level? Junior, Middle, Senior? Why do you think so?

A

I rate myself as Middle developer. On my previous workplace we didn’t have strict grades system, but there are two factors that make me think so.

First, is that I already discussed about that with my teamlead when I was leaving this job. We talked with him about my experience and he said that in his opinion, I am already experienced enough to be Middle level developer.

Second moment, is tasks complexity. If to talk roughly:
- Junior developer can do some simple things following exact instructions and need mentorship in order to keep project from being destroyed.
- Middle developer is experienced and skilled enough to be able to work independently and make decisions on code level without any bad consequences for the project.
- Senior developer is capable to make strategical decisions on system level, lead the development process and teach other developers.

And if follow this gradation, then I am Middle level developer.

137
Q

What are attribute selectors?

A

Attributes selector is a selector which selects certain elements based on their attributes.
Syntax is like: [attribute-name=value]

138
Q

What is neighbour selector?

A

Neighbour selector is a selector which allows to select next element inside same container like:

div + span { … }

139
Q

What is difference between v-model in Vue 2 and Vue 3?

A

In Vue 2 we could have only one v-model, but in Vue 3 we can have multiple v-models

140
Q

What is the difference between monolith and microservices, why one can be better than another?

A

⏩Monolith:

✔️Simple: One codebase, easier to manage.
✔️Fast: No network delays, just quick performance.
✔️Unified: Easier data management.

❌Scaling: Hard to scale parts individually.
❌Changes: One change can affect the whole system.

⏩Microservices:

✔️Scalable: Scale what you need, when you need it.
✔️Flexible: Teams work independently, deploy faster.
✔️Resilient: One service fails, others keep going.

❌Complex: More moving parts to managez.
❌Slow: Network communication can add delays.
❌Data: Keeping everything in sync is tricky.