DEV Community

Cover image for Mock Interview Frontend
karthika jasinska
karthika jasinska

Posted on

Mock Interview Frontend

What Is Ternary Operator In JavaScript & Why Should We Use?

While binary means two, ternary means three. Just like its name, ‘Ternary Operator’ has three components. If you are into JavaScript it is good idea to use ‘Ternary Operator’ to replace simple if else statements.Also this is,

  1. Straight Forward
  2. Clear Code
  3. Saves Time
  4. Less Typing, Five lines of code in one (Who does not like that?)
  5. Professional

Replacing with ‘Ternary Operator’

Ternary Operator definitely has many advantages for simpler if else statements but it is not advisable to use on complex & multiple options conditional statements.

Difference between var, let and const keywords in JavaScript?

JavaScript provides three ways to declare variables: var, let, and const, but they differ in scope, hoisting behaviour, and re-assignment rules.

var: Declares variables with function or global scope and allows re-declaration and updates within the same scope.
let: Declares variables with block scope, allowing updates but not re-declaration within the same block.
const: Declares block-scoped variables that cannot be reassigned after their initial assignment.

JavaScript Data Types?

Mutability vs Immutability in JavaScript?

Mutability:
If a data type is mutable, that means that you can change it. Mutability allows you to modify existing values without creating new ones.

Immutability:
Immutability is the state where values are immutable (that is, not able to be changed). A value is immutable when altering it is impossible. Primitive data types are immutable.

JavaScript Switch Statement?

Switch Control Flow:
Based on a condition, switch selects one or more code blocks to be executed.

switch executes the code blocks that matches an expression.

switch is often used as a more readable alternative to many if...else if...else statements, especially when dealing with multiple possible values.
Example:
const expr = "Papayas";
switch (expr) {
case "Oranges":
console.log("Oranges are $0.59 a pound.");
break;
case "Mangoes":
case "Papayas":
console.log("Mangoes and papayas are $2.79 a pound.");
default:
console.log(Sorry, we are out of ${expr}.);
}

// Expected output: "Mangoes and papayas are $2.79 a pound."

Break Statement:

When JavaScript reaches a break keyword, it breaks out of the switch block.

This will stop the execution inside the switch block.

No more statements in the switch block will be executed.

It is not necessary to break the last case. The switch ends (breaks) there anyway.

Default Statement:

The default keyword specifies a block of code to run if there is no case match.

The default keyword is optional.

CSS Padding vs Margin?

Padding: Adds space inside an element, between its content and border.
Margin: Adds space outside an element, creating gaps between elements.

Difference between CSS Grid and Flexbox?

CSS Grid Layout, is a two-dimensional grid-based layout system with rows and columns. It makes easier to design web pages without having to use floats and positioning. Like tables, grid layout allow us to align elements into columns and rows.

he CSS Flexbox offers one-dimensional layout. It is helpful in allocating and aligning the space among items in a container (made of grids). It works with all kinds of display devices and screen sizes. To get started you have to define a container element as a grid with display: flex;

Top comments (1)

Collapse
 
dev_saravanan_journey profile image
Saravanan Lakshmanan

Useful