22 Most Common Web Developer Job Interview Questions

Lecture



Thorough preparation is one of the key elements of passing an interview successfully, and, incidentally, it is often neglected.

Although this article does not claim to be objective, it covers all the main questions that may be asked on PHP, JS, jQuery, CSS, HTML, MySQL and OOP, along with detailed answers to them.

By studying these topics, you will noticeably improve your theoretical foundation and significantly increase your chances of landing the coveted job.


— How many data types are there in PHP?

PHP supports 8 basic data types.

4 scalar types:

— boolean. A logical data type; variables of this type can take the value true or false.

— integer. An integer data type; variables can take whole values (…-2, -1, 0, 1, 2…) in the range from -2^31 to +2^31. If a value exceeds this limit, it is automatically converted to the float type.

— float. A floating-point numeric data type that can hold both whole and fractional values.

— string. A string data type. It contains a non-fixed number of various characters. PHP imposes no limit on string length, so you can safely work even with VERY large strings.

2 compound types:

— array. An array, which contains an ordered list of elements.

— object. An object, which holds some object (an instance of a class).

2 special types:

— resource. A reference to an abstract element, the so-called external resource. Examples of external resources are a file handle and a query result reference.

— NULL. An empty data type denoting the absence of any value. Such values are usually described as "undefined". Variables of any other type can be initialized with the empty value.


— What is a static function and how does it differ from a "regular" (non-static) one?

A static member belongs to the class, not to an instance of the class. It is called on the class, not on an object, i.e. directly. Declaring class properties and methods as static allows you to access them without creating an instance of the class. A class attribute declared static cannot be accessed through an instance of the class (but a static method can be called). Since static methods are called without creating an instance of the class, the pseudo-variable $this is not available inside a method declared static. Static class properties cannot be accessed through the -> operator.


— Is there a difference between single and double quotes in PHP?

In double quotes the data is "parsed", while in single quotes it is not. In this case, with double quotes Chimay will be output, and with single quotes — $beer.

1

2

$beer = 'Chimay';

echo "$beer";


— Write a program that outputs prime numbers, i.e. numbers divisible without a remainder only by themselves and by 1.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

$lst = array();

$k = "prime";

for ($i = 2; $i < 100; $i++) {

for ($j = 2; $j < $i; $j++) {

if (($i % $j) == 0) {

$k = "not prime";

}

}

if ($k == "prime") $lst[] = $i;

else $k = "prime";

}

foreach($lst as $list) echo $list . "";


— Write a censor program that would replace the words "fuck", "idiot" and "bitch" entered by a user into a form with "f**k", "id**t" and "bi**h".

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

$find = array(

‘fuck’,

‘idiot’,

‘bitch’

);

$replace = array(

‘f * *k’,

‘id * *t’,

‘bi * *h’

);

If (isset($_POST[‘user_input’]) && !empty($_POST[‘user_input’])) {

$user_input = $_POST[‘user_input’];

$user_input_new = str_ireplace($find, $replace, $user_input);

echo $user_input_new;

}


— What are dynamic variables?

A dynamic variable is one whose name is stored in another variable. This is the so-called "variable variable". For example:

1

2

3

$var = "first";

$$var = "Second";

// $$var == $first == "Second"

$$var is dynamic; its name can change along with $var. You can also bind a variable name to the contents of another variable implicitly:

1

2

3

4

$first = "second";

$second = "third";

print $first; // prints "second"

print $$first; // prints "third"


— What are design patterns?

A design pattern is a general, typical solution to a problem that recurs repeatedly when designing the architecture of a software product. Patterns show the relationships and interactions between classes and make a system flexible and easy to change. Their proper use increases the reuse rate of ready-made solutions.


— Write an example of implementing polymorphism.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

Class One

{

function foo()

{

echo “Hellofromclass One!”;

}

function callMe()

{

$this->foo();

}

}

Class Two extends One

{

function foo()

{

echo “Hellofromclass Two”;

}

}

$Two = new two();

$Two->callMe();


— What programming paradigms (models, approaches) are there besides OOP?

The most common ones are functional, aspect-oriented and procedural.


— You need to show a message in an alert 3 seconds after the script starts. How do you do it?

Like this:

1

setTimeout(alert(“Hello”), 3000);

Or like this:

1

setTimeout(function() {alert(“Hello”)}, 3000);


— Tell us a few words about objects in JavaScript

Objects (also known as associative arrays or hashes) and working with them in JavaScript are implemented differently than in most languages. An object in JavaScript is an ordinary associative array or, in other words, a "hash". It stores any "key => value" mappings and has several standard methods.


— There are two functions. Is there a difference between them? If so, what is it?

1

function f(a,b) { return a+b }

and

1

var f = function(a,b) { return a+b }

There is a difference, and it lies in the visibility of the function. The variant without var is visible everywhere in the current scope, including before the function's definition. The variant with var assigns the function to a variable, so such a function is visible only after the definition.


— What will the code do: break me_baby; ?

It will exit the current loop or switch block to the label "me_baby".


— What is SQL injection?

SQL injection is the embedding of malicious code into database queries. Using SQL injection, an attacker can not only obtain private information from the database but, under certain conditions, also modify it. Vulnerability to SQL injection arises because user input gets into a database query without proper processing: to keep a script from being vulnerable, you need to make sure that all user data enters all database queries in escaped form.


— Suppose you have an online store. Write a query that shows how much money each individual customer has brought in total over the entire lifetime of the store.

1

2

3

SELECT customer_name, SUM(order_price)

FROM orders

GROUP BY customer_name;


— What is the difference between #my and .my?

#my is an ID selector.

.my is a class selector.


— What are pseudo-classes?

Pseudo-classes are what is usually written after a selector, separated by a colon, to define a reaction or state for that selector. The best-known pseudo-classes are :link, :hover, :visited and :active. Pseudo-classes have the following structure:

1

2

3

selector:pseudo class {

property: value;

}

i.e. you only need to put a colon between the selector and the pseudo-class.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

a.snowman:link {

color: blue;

}

a.snowman:visited {

color: purple;

}

a.snowman:active {

color: red;

}

a.snowman:hover {

text-decoration: none;

color: blue;

background-color: yellow;

}


— Find all div elements with the class one, as well as all p elements with the class two, then add the class three to all of them and smoothly slide them down.

1

$(“div.one”).add(“p.two”).addClass(“three”).slideDown(“slow”);


— Select the divs that do not have the class cls

1

$(‘div:not(.cls)’);


— What is DOCTYPE and why is it needed?

DOCTYPE is a document type declaration (Document Type Definition (DTD)), the rules against which a particular XML or (X)HTML document (web page) is validated. Thanks to this declaration, the browser determines which DTD version the document uses. It is needed so that browsers render the document markup correctly. If no DOCTYPE is specified, the browser will add its own "improvisation", and each browser will add its own. As a result, there can be no talk of any cross-browser compatibility.


— What are entities?

Entities are combinations of the & sign followed by an alphabetic or numeric code, intended to stand in for characters that cannot appear in "plain" form in HTML text, for example the "<" character.


— What magic methods do you know? What are they anyway?

These are methods reserved in PHP that begin with a double underscore "__".

List of all magic methods:

  • __construct
  • __destruct
  • __call
  • __callStatic
  • __get
  • __set
  • __isset
  • __unset
  • __sleep
  • __wakeup
  • __toString
  • __set_state
  • __clone

__construct and __destruct are the most popular methods, which implement basic concepts of object-oriented programming: the constructor and the destructor;

__call, __callStatic, __get and __set are methods related to overloading access to both properties
and methods. The __get() and __set() methods are called when a property value is read or set,
and the __call() and __callStatic methods are called when a method is invoked. Note that these magic functions
will be called only and exclusively when the requested method or property
does not exist;

__isset is a method triggered when the empty() or isset() functions are called on a nonexistent
or inaccessible class property;

__unset is triggered when the unset() function is called on a nonexistent or inaccessible class property;

__sleep and __wakeup are methods called only from the serialize and unserialize functions,
respectively. The __sleep method is called immediately when the serialize function is applied to an object, and
the __wakeup method when unserialize is applied. Currently these methods are used to save the current state of the system with subsequent restoration of that state
(for example, a database connection);

__toString is a method that lets you treat a class as a string (for example, with
print or echo);

__set_state is a method called for classes exported by the var_export()
function, to export property values;

__clone is called when an object is cloned (introduced because objects
in PHP 5 and above are passed by reference);

__invoke is called when an attempt is made to use an object as a function.

Comments

To leave a comment

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

Lectures and tutorial on "Running server side scripts using PHP as an example (LAMP)"

Terms: Running server side scripts using PHP as an example (LAMP)