Professional Documents
Culture Documents
Engineering PDF
Engineering PDF
1. Justify why Semantic elements are preferred over <div> element in HTML.
Semantic elements are HTML elements that have a meaningful name that describes their
content or function, such as <header>, <article>, <nav>, etc.
● <div> element is a generic container that can be used to group any HTML elements, but
it does not convey any information about its content or purpose.
● Semantic elements are preferred over <div> element in HTML because they:
a. Improve readability of the HTML code for both developers and browsers
b. Enhance accessibility for users who rely on screen readers or other assistive
technologies
c. Boost SEO (Search Engine Optimization) by providing relevant keywords and
structure for search engines to index and rank the web pages
d. Facilitate styling by reducing the need for class or id attributes and enabling the
use of CSS selectors based on semantic elements
2. How does the grid system work in bootstrap? Illustrate with the help of an example.
The grid system in bootstrap is a layout system that allows you to create responsive web pages
that can adapt to different screen sizes and devices
● The grid system is based on 12 columns that can be divided into rows and nested inside
each other
● The grid system uses predefined classes that specify the width, alignment, offset, and
order of the columns for different breakpoints (screen widths)
● For example, the following HTML code creates a three-column layout that spans the
entire width of the screen on extra small devices, half of the screen on small devices,
and one-third of the screen on medium and large devices:
JavaScript variables are containers that store data values that can be accessed and
manipulated by the program, these variables can be declared using three keywords:
var, let, and const
● The scope of a variable is the region of the code where the variable can be accessed
and used
a. Global scope: A variable declared outside any function or block is in the global
scope and can be accessed by any part of the code
b. Function scope: A variable declared inside a function using the var keyword is in
the function scope and can only be accessed within that function or by nested
functions
c. Block scope: A variable declared inside a block (a code section enclosed by curly
braces) using the let or const keyword is in the block scope and can only be
accessed within that block or by nested blocks
This code illustrates the differences in scope for variables in JavaScript - global, function, and
block scope.
Laravel is a PHP framework that provides a set of tools and libraries for building web
applications
jQuery getters and setters are methods for accessing and modifying values or attributes of
elements. They set values when provided an argument and retrieve values when no argument
is given. jQuery getters and setters encompass four types of functionalities which involve
manipulating various aspects of elements in the DOM:
● HTML content methods like .html(), .text(), .append(), .prepend(), etc., handle the
alteration of HTML content within selected elements.
● CSS properties methods like .css(), .addClass(), .removeClass(), .toggleClass(), etc.,
manage the modification of CSS properties for targeted elements.
● DOM attributes methods like .attr(), .prop(), .val(), .removeAttr(), etc., facilitate the
manipulation of DOM attributes within selected elements.
● Data attributes methods such as .data(), .removeData(), etc., allow manipulation of data
attributes associated with elements.
JavaScript: // setter: sets the text content of all the <p> elements to "Hello"
$("p").text("Hello");
To add an object in an array using JavaScript, you can use one of the following methods:
● push(): This method adds one or more elements to the end of an array and returns the
new length of the array. For example:
● unshift(): This method adds one or more elements to the beginning of an array and
returns the new length of the array. For example:
● splice(): This method inserts or deletes elements at a specified index of an array and
returns an array of the deleted elements. To insert an element without deleting any, you
can pass 0 as the second argument. For example:
A navigation bar is a header that contains links to navigate through a website or an application.
Bootstrap provides a component called .navbar that allows you to create responsive and
customizable navigation bars.
● Make a `<nav>` element with class `.navbar` and a color scheme class.
● Include a `<div>` with class `.container-fluid` inside the `<nav>` for navigation bar
content.
● Add a `<div>` with class `.navbar-header` to hold the brand/logo using `<a>` with class
`.navbar-brand`.
● Create a `<button>` with class `.navbar-toggler` to toggle navigation links on smaller
screens.
● Inside, add a `<div>` with classes `.collapse` and `.navbar-collapse` to contain
collapsible navigation links.
● Use `<ul>` with class `.navbar-nav` to hold navigation links and create dropdown menus
if needed.
Additionally, for forms or buttons, use `<form>` or `<button>` elements with class `.form-inline`
inside `.navbar-collapse`. Adjust alignment with `.mr-auto` or `.ml-auto`.
HTML: <html>
<head>
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>
jQuery utility functions are methods that are defined on the jQuery object ($) and can be used
for various purposes, such as iterating over arrays or objects, checking the type of a value,
extending objects, etc.
● $.each(): This function iterates over an array or an object and invokes a callback function
for each element or property. The callback function receives the index and the value as
arguments and can return false to stop the iteration. For example:
● $.extend(): This function merges the properties of two or more objects into the first object
and returns the modified object. If the same property exists in more than one object, the
value from the last object will overwrite the previous ones. To create a new object without
modifying any of the existing objects, you can pass an empty object as the first
argument. For example:
DOM stands for Document Object Model, which is a standard interface for representing and
manipulating HTML, XML, and SVG documents.
● DOM objects are the nodes or elements that make up the tree-like structure of a
document.
● Each DOM object has a set of properties and methods that can be accessed and
modified by JavaScript.
For example, the following HTML code creates a simple document with a heading and a
paragraph:
HTML:<html>
<head>
<title>DOM Example</title>
</head>
<body>
<h1 id="title">Hello, World!</h1>
<p id="content">This is a DOM example.</p>
</body>
</html>
● To access and manipulate the DOM objects, we can use the document object, which
represents the entire document and provides various methods and properties.
For example:
JavaScript is a programming language that can be used to create dynamic and interactive web
pages and applications. It can run on both the client-side and the server-side, depending on the
environment.
● Versatile language: used for web development, game development, mobile apps, etc.
● Compatible with HTML, CSS, and various frameworks/libraries.
● Lacks built-in MVC support, but achievable via different libraries/frameworks.
● Doesn't natively support data binding but achievable with various libraries.
● Lacks native dependency injection support, but achievable with different libraries.
MVC stands for Model-View-Controller, which is a design pattern that separates an application
into three main components: Model, View, and Controller. Each component has a specific role
and responsibility in the application.
● The Model component manages data, validates it, and performs operations without
direct user interaction, communicating with the Controller.
● The View component displays data, receives user input, and generates output without
containing business logic, communicating with the Controller.
● The Controller component mediates between the Model and View, handling user
requests, invoking Model methods, passing data to the View, controlling application flow
and behavior.
● Clear separation of concerns by organizing code into reusable and modular components
for better code management.
● Enhanced maintainability and testability as each component can be independently
tested and modified, simplifying maintenance.
● Improved scalability and performance by distributing components across servers or
machines, optimizing resource use.
● Support for multiple views allowing different user interfaces for various devices,
enhancing user experience.
● Increased complexity and learning curve for developers understanding component roles
and interactions.
● Potential code overhead and duplication with data transfer between components, raising
codebase complexity.
● Challenges implementing non-MVC features make integrating complex user interactions
difficult, limiting system flexibility.