Does it work?

Let’s have some fun with theory. Just look at the five following codes (test them only after playing the game). Does it work or not?

To see the answer, click on the collapsible “answer”.

HTML quotes or not?

Here is the most basic HTML markup for a link:

<a href=https://google.com>go to google.com</a>

It seems there are no quotes on the href attribute, but does the link work?

Php switch

Look at the following PHP code:

<?php
$number = 73;
switch($number)
{
case 73.0:
    echo "héhé";
case 73:
    echo " I'm not surprised";
    break;
default:
    echo "what?!!!";
}
?>

I say you get “héhé I’m not surprised” with that. Am I right? Does the code even work without throwing any errors?

Ruby conditions

I want to execute some code under specific conditions. I’ve found something in the documentation. It’s called unless:

MY_CODE unless MY_CONDITION

Will this work like I want?

Python comprehension

Python has a pretty cool way to handle lists called “List Comprehension”. Instead of using a for loop that can be annoying to write, you can use a special syntax for better readability.

For example, let’s say we want to put the following text that someone had better say in a list:

Kesher = "This is the girl"
k = [i.lower() for i in Kesher]
print(k)

Kesher is a string, and we put each character, including spaces, in the list using just a line of code. We also apply the lower function to each element at the same time.

Looks neat, but is that possible? Only one line of code?

JavaScript evaluation

They say JavaScript operators short-circuit. What does it mean?

When the first operand of your condition is true, the engine skips the remaining operands. Reciprocally, if it’s false, the engine will continue evaluating.

Let’s keep it simple. && and || are standard logical operators. They respectively mean “and” and “or”.

Instead of using if-else statements, you can leverage the benefits of short-circuit evaluation. For example:

const responseObject = { success: false };
!responseObject.success && console.error('oooops!');

Now, look at this stupid example:

let apple = "m1", 
    intel, 
    chip = null,
    battle = undefined,
    winner = chip || intel || battle || apple;
    
console.log(winner)

Does it work? Do I get my m1?

Wrap up

I hope you enjoyed those questions, but I lied a little bit. It’s not only for fun. It is the kind of questions you might get during job interviews.

Photo by Sigmund on Unsplash