CSS JavaScript Exam Notes
CSS JavaScript Exam Notes
CSS (Cascading Style Sheets) is a language used to describe the presentation of web pages written in HTML
or XHTML. It allows web developers to control the layout, style, and appearance of elements on a web page.
CSS is not part of HTML itself but is used to enhance and modify how HTML content is displayed in the
browser. CSS started with version 1 in 1996, evolved to CSS2 in 1998, and continues to develop with CSS3.
There are three main ways to apply CSS to a web page. Inline CSS applies styles directly within HTML tags
using the 'style' attribute, giving it the highest priority. Document-level CSS is placed within a <style> tag
inside the <head> section of the document, affecting the entire page. External CSS is written in separate .css
files and linked to multiple web pages, ensuring consistency across a website.
CSS rules consist of selectors and declarations. Selectors target HTML elements, and declarations define the
properties and values to be applied. These selectors can be simple, like using tag names, or more specific
like class selectors (using a dot prefix), id selectors (with a hash prefix), or pseudo-classes that respond to
Fonts and text in CSS can be customized extensively. Properties like font-size, font-family, and text-align
control appearance. Colors can be set using names, hexadecimal values, or RGB. The box model is a
fundamental concept in CSS, defining how margins, borders, padding, and content interact to determine an
CSS also allows styling lists, aligning text, and using background images. Additional tools like the <span>
and <div> tags allow developers to apply styles to specific inline or block-level sections of content. When
multiple style rules apply, CSS uses a cascade mechanism to resolve conflicts based on rule specificity and
origin.
JavaScript
JavaScript is a lightweight, interpreted programming language primarily used to create dynamic and
CSS and JavaScript - Exam Notes
interactive effects within web browsers. Initially developed by Netscape as LiveScript, it was standardized
under the name ECMAScript. JavaScript is widely supported by all modern browsers and plays a crucial role
in client-side scripting.
One of the most important aspects of JavaScript is that it is loosely typed and event-driven. This means that
variables do not require type declarations, and much of the code is designed to respond to user interactions,
such as clicks or keypresses. It is embedded in HTML documents, either within the <script> tag or by
JavaScript supports several core data types, including numbers, strings, booleans, undefined, and null. It
includes arithmetic and logical operators, and statements can include control structures like if-else,
switch-case, and loops such as for, while, and do-while. Functions in JavaScript are first-class objects,
meaning they can be assigned to variables, passed as parameters, or returned from other functions.
Objects in JavaScript are collections of properties and methods, and new objects can be created either using
constructor functions or object literals. Arrays are dynamic and can hold mixed data types. JavaScript also
includes built-in objects like Date, Math, and String, which provide various utility methods.
User input and output in JavaScript are handled through functions like alert, confirm, and prompt. The
Document Object Model (DOM) allows JavaScript to interact with HTML and CSS to manipulate the content
and style dynamically. Regular expressions offer powerful pattern matching capabilities for validating input or
searching text.
JavaScript plays a vital role in form validation, ensuring user input is correct before sending it to a server.
Despite its client-side nature, crucial validation must still be handled server-side, as client-side scripts can be
bypassed. Debugging JavaScript involves using browser tools and understanding common errors and their
causes.