Vision Waves
Vision Waves
1. What is HTML?
o HTML (HyperText Markup Language) is the standard language used to create
web pages. It provides the structure and content of a webpage, such as headings,
paragraphs, images, links, etc.
2. What is the purpose of the <!DOCTYPE html> declaration?
o It tells the browser that the document is an HTML5 document. It helps the
browser render the page correctly.
3. What are the basic structure elements of an HTML document?
o <html>, <head>, and <body>. The <html> element is the root, <head> contains
metadata like title, and <body> contains the visible content.
4. What is the difference between an id and a class in HTML?
o id is unique and used for one element, while class can be used for multiple
elements.
5. What is a semantic element in HTML? Give examples.
o Semantic elements provide meaning to the content. Examples: <header>,
<footer>, <article>, <section>.
6. What are attributes in HTML?
o Attributes provide additional information about an element, like src for images or
href for links.
7. What is the use of the <meta> tag in HTML?
o It provides metadata like character set, author, or description of the page, and
helps with SEO.
8. What is the difference between block-level and inline elements?
o Block-level elements take up the full width and start on a new line, e.g., <div>.
Inline elements take only as much width as necessary, e.g., <span>.
9. What is an anchor tag in HTML?
o The <a> tag is used to create hyperlinks. Example: <a
href="https://www.example.com">Click Here</a>.
10. What is the purpose of the <form> element?
o It is used to collect user input, such as text, checkboxes, or radio buttons.
11. What are input types in HTML forms? Name a few.
o Input types specify the type of data to be entered. Examples: text, password,
email, checkbox, radio.
12. How do you create a hyperlink in HTML?
o Use the <a> tag: <a href="https://www.example.com">Visit Example</a>.
13. What is the <head> tag used for?
o The <head> tag contains metadata like the title, styles, and scripts, not visible on
the page.
14. What are tables used for in HTML?
o Tables are used to display tabular data. They are created with <table>, <tr>,
<td>, and <th> tags.
15. How do you add an image in HTML?
o Use the <img> tag with a src attribute: <img src="image.jpg"
alt="description">.
16. What is the <title> tag used for?
o The <title> tag sets the title of the webpage, displayed in the browser tab.
17. What is the difference between <div> and <span>?
o <div> is a block-level element, while <span> is an inline element.
18. What are the types of lists in HTML?
o There are three types: ordered (<ol>), unordered (<ul>), and description (<dl>).
19. What is the role of the alt attribute in images?
o The alt attribute provides alternative text when the image cannot be displayed.
20. What are iframes and how are they used in HTML?
o <iframe> is used to embed another HTML document within the current
document.
21. What is the difference between the <link> and <script> tags?
o <link> is used to link external resources like CSS files, while <script> is used
to link or embed JavaScript.
22. How do you create a dropdown menu in HTML?
o Use the <select> element with <option> elements:
html
Copy code
<select>
<option value="option1">Option 1</option>
<option value="option2">Option 2</option>
</select>
html
Copy code
<video controls>
<source src="video.mp4" type="video/mp4">
</video>
html
Copy code
<table>
<tr>
<th>Header</th>
</tr>
<tr>
<td>Data</td>
</tr>
</table>
html
Copy code
<input type="text" required>
1. What is CSS?
o CSS (Cascading Style Sheets) is used to style and layout web pages, including
colors, fonts, and positioning.
2. What are selectors in CSS?
o Selectors are patterns used to select and apply styles to HTML elements.
Examples: .class, #id, element.
3. What is the difference between class and id selectors?
o class is reusable (used for multiple elements), while id is unique (used for one
element).
4. What is the box model in CSS?
o The box model consists of content, padding, border, and margin, which determine
the size of an element.
5. How do you apply CSS to an HTML element?
o You can apply CSS via inline styles, internal style sheets, or external CSS files.
6. What is the z-index in CSS?
o z-index controls the stacking order of elements. Higher values are displayed on
top.
7. What are pseudo-classes in CSS? Give examples.
o Pseudo-classes style elements based on their state, such as :hover, :focus,
:nth-child().
8. What are pseudo-elements in CSS? Give examples.
o Pseudo-elements style parts of an element, such as ::before, ::after, and
::first-letter.
9. What is the display property in CSS?
o The display property controls how elements are displayed (e.g., block, inline,
flex).
10. What is the difference between visibility and display in CSS?
o visibility: hidden hides an element but it still takes up space, while
display: none removes the element from the layout.
11. How do you center a div element horizontally and vertically?
o Use Flexbox or Grid. Example with Flexbox:
css
Copy code
.container {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
css
Copy code
body {
background-image: url('image.jpg');
}
css
Copy code
* {
color: black;
}
css
Copy code
@font-face {
font-family: 'MyFont';
src: url('myfont.ttf');
}
33. What are transitions in CSS?
o Transitions allow changes to occur over a specific duration, such as changing
color on hover.
34. What is the difference between transition and animation in CSS?
o Transitions occur when an element changes state (e.g., hover), while animations
are continuous or triggered by a specific event.
35. How can you make text bold in CSS?
o Use the font-weight property: font-weight: bold;.
1. What is JavaScript?
o JavaScript is a programming language used to make web pages interactive by
manipulating the DOM.
2. What is the difference between var, let, and const?
o var is function-scoped and can be redeclared. let is block-scoped and can be
reassigned. const is block-scoped and cannot be reassigned.
3. What is a JavaScript function?
o A function is a reusable block of code that performs a specific task.
4. How do you declare a variable in JavaScript?
o Use var, let, or const:
javascript
Copy code
let x = 5;
javascript
Copy code
let fruits = ['apple', 'banana'];
javascript
Copy code
for (let i = 0; i < 5; i++) {
console.log(i);
}
javascript
Copy code
let person = {
name: 'John',
greet: function() { console.log('Hello!'); }
};
javascript
Copy code
const sum = (a, b) => a + b;
javascript
Copy code
function outer() {
let count = 0;
return function inner() {
count++;
console.log(count);
}
}
const counter = outer();
counter(); // 1
javascript
Copy code
try {
let x = 1 / 0;
} catch (error) {
console.error(error);
}
javascript
Copy code
const element = document.querySelector('.my-class');
html
Copy code
<script src="script.js"></script>
javascript
Copy code
element.addEventListener('click', function() {
console.log('Element clicked!');
});
The Fetch API is used to make network requests and handle responses:
javascript
Copy code
fetch('https://api.example.com/data')
.then(response => response.json())
.then(data => console.log(data));
forEach iterates over an array but does not return a new array. map iterates and returns a
new array with modified elements.
JavaScript modules allow you to split code into reusable pieces using export and
import.
32. What is destructuring in JavaScript?
javascript
Copy code
const [a, b] = [1, 2];
const {name, age} = {name: 'John', age: 30};
javascript
Copy code
const greeting = `Hello, ${name}!`;
34. What is the difference between call, apply, and bind in JavaScript?
The Event Loop is responsible for executing code, handling events, and managing
asynchronous tasks by checking the call stack and task queue.
Here are some of the most commonly asked JavaScript interview questions:
Hoisting is JavaScript's default behavior of moving declarations to the top of the current
scope (function or global). Variable and function declarations are hoisted, but only the
declarations (not the initializations) are moved.
Example:
javascript
Copy code
console.log(x); // undefined
var x = 5;
console.log(x); // 5
A closure is a function that "remembers" its lexical scope even when the function is
executed outside that scope. Example:
javascript
Copy code
function outer() {
let x = 10;
return function inner() {
console.log(x);
};
}
const closureFunc = outer();
closureFunc(); // 10
The this keyword refers to the context (object) in which the function is called. The value
of this is determined by how a function is invoked.
Example:
javascript
Copy code
const person = {
name: 'John',
greet: function() {
console.log(this.name);
}
};
person.greet(); // 'John'
javascript
Copy code
let promise = new Promise(function(resolve, reject) {
let success = true;
if (success) {
resolve("Operation was successful");
} else {
reject("Operation failed");
}
});
promise.then(function(result) {
console.log(result); // "Operation was successful"
}).catch(function(error) {
console.log(error); // "Operation failed"
});
javascript
Copy code
5 == '5'; // true
5 === '5'; // false
The bind() method creates a new function that, when called, has its this keyword set to
a specific value, and prepends any arguments to the function call. Example:
javascript
Copy code
const obj = {name: 'John'};
function greet() {
console.log(this.name);
}
const greetBound = greet.bind(obj);
greetBound(); // 'John'
Example:
javascript
Copy code
document.getElementById('parent').addEventListener('click', function(e) {
if (e.target && e.target.matches('button.classname')) {
console.log('Button clicked');
}
});
Example:
javascript
Copy code
let a;
console.log(a); // undefined
let b = null;
console.log(b); // null
Example:
javascript
Copy code
let name = "John"; // String
let age = 30; // Number
let isActive = true; // Boolean
let obj = null; // Null
The typeof operator returns a string indicating the type of the unevaluated operand.
Example:
javascript
Copy code
console.log(typeof 42); // "number"
console.log(typeof "Hello"); // "string"
console.log(typeof true); // "boolean"
console.log(typeof undefined); // "undefined"
console.log(typeof {a: 1}); // "object"
The spread operator (...) is used to expand or spread the elements of an iterable (array,
object) into individual elements or properties.
Example:
javascript
Copy code
const arr1 = [1, 2, 3];
const arr2 = [...arr1, 4, 5];
console.log(arr2); // [1, 2, 3, 4, 5]
const obj1 = { a: 1, b: 2 };
const obj2 = { ...obj1, c: 3 };
console.log(obj2); // { a: 1, b: 2, c: 3 }
Arrow functions are a more concise way of writing functions in JavaScript, and they do
not have their own this context.
Example:
javascript
Copy code
const add = (a, b) => a + b;
console.log(add(2, 3)); // 5
Synchronous code is executed sequentially, blocking the execution of other code until it
finishes. Asynchronous code allows the program to continue executing other tasks while
waiting for a task to finish.
Example:
javascript
Copy code
console.log("Start");
// Synchronous
for (let i = 0; i < 3; i++) {
console.log(i);
}
console.log("End");
The setTimeout() function allows you to execute code after a certain amount of time.
Example:
javascript
Copy code
setTimeout(() => {
console.log("This runs after 2 seconds");
}, 2000);
15. What is the difference between apply() and call() methods in JavaScript?
Both call() and apply() are used to invoke functions, but apply() takes an array of
arguments while call() takes individual arguments.
Example:
javascript
Copy code
function greet(message, name) {
console.log(`${message}, ${name}`);
}