Intro Flashcards

1
Q

Why did you change your career path from Biomedical Science to Computer Science?

A

As much as I enjoyed studying biomedical science, I always felt a tiny part of me was missing that true passion that you enjoy what you are working on. So, I had some time to reflect on myself and I realised that my true passion lies in technology. In every aspect of my life since technology appeared, I always had this fascination about it and desire to know more. I found that this field is a great fit for my skills and interests.

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

What is JavaScript, and what are its key features?

A

JavaScript is a programming language used to create interactive and dynamic elements on websites. Its key features include client-side scripting, cross-platform compatibility, event-driven programming, DOM manipulation, asynchronous programming, and support for third-party libraries and frameworks.

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

How does JavaScript differ from other programming languages?

A

JavaScript differs from other programming languages in several ways:

Interpretation and Execution: JavaScript is typically executed by web browsers rather than being compiled. This allows for faster development cycles as code changes can be immediately tested without the need for compilation.

Client-Side Execution: JavaScript is primarily used for client-side scripting, running on the user’s web browser. This enables dynamic interaction and manipulation of web page elements without requiring server-side processing.

Focus on Web Development: While JavaScript can be used for other purposes like server-side scripting (Node.js), it is primarily associated with web development. It offers specific features and APIs for working with the Document Object Model (DOM), handling events, and making AJAX calls.

Weak Typing and Dynamic Typing: JavaScript is loosely typed, meaning variables can hold values of different types and can change type during runtime. This flexibility can simplify development but also requires careful handling to avoid unexpected behavior.

Prototype-based Object-Oriented Programming: JavaScript uses a prototype-based approach to object-oriented programming rather than class-based inheritance. Objects can be created directly from existing objects, allowing for flexible object creation and behavior modification.

Functional Programming Support: JavaScript supports functional programming paradigms, allowing functions to be treated as first-class objects, supporting higher-order functions, closures, and immutable data structures.

Widespread Browser Support: JavaScript is supported by all major web browsers, making it a widely accessible language for web development.

These differences make JavaScript unique and suitable for developing interactive web applications.

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

What are the different data types in JavaScript?

A

JavaScript has several built-in data types, including:

Number: Represents numeric values, including integers and floating-point numbers.

String: Represents a sequence of characters enclosed in single quotes (‘’) or double quotes (“”).

Boolean: Represents either true or false, used for logical operations and conditional statements.

Null: Represents the intentional absence of any object value.

Undefined: Represents a variable that has been declared but not assigned a value.

Object: Represents a collection of key-value pairs and can include functions, arrays, and other objects.

Array: Represents an ordered list of values, accessible by numeric indices.

Function: Represents a reusable block of code that performs a specific task.

Symbol: Represents a unique identifier, often used as keys for object properties.

These data types provide the foundation for storing and manipulating different kinds of data in JavaScript.

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

Explain the difference between null and undefined in JavaScript.

A

null represents the intentional absence of any object value and is assigned explicitly by the programmer. undefined represents the absence of an assigned value and is automatically assigned by JavaScript when a variable is declared but not initialized.

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

What is the purpose of the “use strict” directive in JavaScript?

A

The “use strict” directive enables strict mode in JavaScript, enforcing stricter rules and catching common mistakes to improve code quality and reliability.

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

How do you declare variables in JavaScript? What are the differences between var, let, and const?

A

Variables in JavaScript can be declared using var, let, or const. var has function or global scope and allows redeclaration and reassignment. let has block scope and allows reassignment but not redeclaration. const also has block scope but is used for variables that remain constant and cannot be reassigned.

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

Explain the concept of hoisting in JavaScript.

A

Hoisting is a JavaScript behavior where variable and function declarations are moved to the top of their scope during the compilation phase. Variables declared with var are hoisted, meaning they can be accessed before they are declared, but their assignments remain in place. Function declarations are also hoisted, allowing them to be called before they are defined. However, variables declared with let or const are not hoisted.

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

What are the different ways to create objects in JavaScript?

A

There are different ways to create objects in JavaScript:

Object Literal: Objects can be created using curly braces and defining key-value pairs.
Constructor Function: Objects can be created using regular functions with the new keyword.
Object.create(): The Object.create() method creates a new object with a specified prototype.
Class: Introduced in ES6, classes provide a syntax for creating objects with constructor functions and additional features.

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

How do you handle asynchronous operations in JavaScript? Provide examples.

A

Asynchronous operations in JavaScript can be handled using callbacks, Promises, or async/await.

Callbacks:
fetchData(function (data) {
console.log(data);
});

Promises:
fetchData()
.then(function (data) {
console.log(data);
});

Async/Await:
async function processData() {
const data = await fetchData();
console.log(data);
}

processData();

Callbacks provide a traditional approach, Promises offer better control flow, and async/await provides a more synchronous-like coding style for handling asynchronous operations.

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

Explain the concept of closures in JavaScript and provide an example

A

Closures in JavaScript allow functions to retain access to variables from their outer scope even after the outer function has finished executing.

function outerFunction() {
const outerVariable = “Hello”;

function innerFunction() {
console.log(outerVariable);
}

return innerFunction;
}

const myFunction = outerFunction();
myFunction(); // Outputs: “Hello”

The inner function innerFunction has access to the outerVariable from its enclosing scope, creating a closure. The closure allows innerFunction to access and use the outerVariable even after outerFunction has completed.

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

How does prototypal inheritance work in JavaScript?

A

Prototypal inheritance in JavaScript allows objects to inherit properties and methods from other objects. Each object has a [[Prototype]] property that points to another object. When a property is accessed on an object, JavaScript checks the object itself first, and if not found, it looks up the prototype chain until it finds the property or reaches the end.

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

What is the Event Loop in JavaScript, and how does it handle asynchronous operations?

A

The Event Loop is a fundamental mechanism in JavaScript that handles asynchronous operations. It ensures that code execution continues while asynchronous tasks are being processed in the background.

Here’s a simplified explanation:

JavaScript code is executed line by line.
Asynchronous operations are scheduled to run in the future and are moved out of the main thread.
The rest of the code continues executing.
Once an asynchronous operation completes, it is placed in the task queue.
The Event Loop constantly checks if the call stack is empty.
If the call stack is empty, tasks from the task queue are pushed onto the call stack for execution.
This process allows JavaScript to handle asynchronous tasks without blocking the main thread and keeps the code responsive.

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

Describe the difference between synchronous and asynchronous code execution in JavaScript.

A

Synchronous code execution runs line by line, blocking subsequent code execution until each line is completed. Asynchronous code execution allows operations to run in the background while the program continues to execute other code without waiting for their completion. Asynchronous operations are typically scheduled for future execution and utilize callbacks, Promises, or async/await to handle their results.

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

How do you handle errors in JavaScript? What are the error handling mechanisms available?

A

In JavaScript, errors can be handled using try…catch statements, throwing errors using the throw statement, using built-in error objects, and error event handlers. Try…catch statements catch exceptions within a block of code, while the throw statement manually throws an error. Built-in error objects provide additional information about errors, while error event handlers handle errors that occur during asynchronous tasks. Promises and async/await can also handle errors using the catch block or try…catch statements.

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

Explain the concept of callback functions in JavaScript. Provide an example.

A

Callback functions in JavaScript are functions passed as arguments to other functions and executed later when a specific event or condition occurs. They allow us to define custom behavior for asynchronous operations or events.

17
Q

What are the different methods available for iterating over an array in JavaScript?

A

In JavaScript, there are multiple methods for iterating over an array:

for loop: The traditional for loop allows you to iterate over an array using an index variable.

forEach(): Executes a provided function for each array element.

for…of loop: A newer iteration feature that simplifies array iteration.

map(): Creates a new array by applying a provided function to each element.

filter(): Creates a new array with elements that pass a test condition.

reduce(): Applies a function to accumulate a single value while iterating over the array.

These methods offer different ways to loop through an array and process its elements based on your specific requirements.

18
Q

Describe the concept of arrow functions in JavaScript and how they differ from regular functions.

A

Arrow functions in JavaScript provide a concise syntax for writing functions. They have an implicit return feature and lexically bind the value of this. This makes them convenient for short, inline functions and avoids the need for explicit return statements and this binding.

19
Q

What is the purpose of the “this” keyword in JavaScript?

A

The this keyword in JavaScript refers to the current object or context in which a function is being executed. It allows access to object properties and methods, facilitates constructor functions, handles events, and enables explicit binding.

20
Q

Explain the concept of the DOM (Document Object Model) and how JavaScript interacts with it.

A

The DOM (Document Object Model) is a programming interface for web documents that represents the structure of an HTML or XML document as a tree-like structure. JavaScript interacts with the DOM by using built-in APIs and methods to access, modify, and manipulate the document’s elements, attributes, content, and styles. It can select elements, manipulate their properties, create new elements, handle events, traverse the DOM tree, and dynamically change styles. JavaScript’s interaction with the DOM enables dynamic and interactive web development.

21
Q

How can you manipulate CSS styles dynamically using JavaScript?

A

To manipulate CSS styles dynamically in JavaScript, you can directly modify the style property of DOM elements. You can set individual CSS properties, add or remove CSS classes, toggle classes, or assign inline style strings. These manipulations allow you to change the appearance of elements based on user interactions or dynamic conditions.

22
Q

What do you think a good performance is?

A
  • I have met or exceeded the expectations set out for me
  • delivering high-quality work in a timely manner
  • strong work ethic and positive attitude
  • taking ownership of my responsibilities
  • being proactive in finding solutions to challenges that arise
  • effective communication with colleagues
  • building strong relationships
  • being open to constructive feedback in order to continuously improve