Csi Revision: 1. Declaring Variables in Javascript
Csi Revision: 1. Declaring Variables in Javascript
● var is the older way to declare variables. It is function-scoped, meaning it can be accessed
anywhere inside the function where it is declared.
● let is a newer way and is block-scoped, meaning it only works within the block (e.g., inside a
loop or condition) where it is declared.
● const is used for values that cannot be changed once declared. It is also block-scoped.
Example:
In JavaScript, we can declare variables using the var keyword along with the variable name. For
example, var fname declares a variable named fname. You can assign a value to the variable either
at the time of declaration or later. to declare two variables, num and name, and assign values to
them.
var num;
var name;
num = 2;
name = "Natasha";
2. What is Python? What are its Features?
Python is a high-level, interpreted programming language known for its simplicity and readability. It is
widely used in web development, data analysis, artificial intelligence, automation, and more. Python
uses a clean and easy-to-understand syntax, which makes it easy to understand for beginners
● Easy to learn: Python has a straightforward syntax that is easy for beginners to understand.
● Extensive libraries: Python offers libraries for various tasks,
● Cross-platform compatibility: Python runs on many operating systems such as Windows,
macOS, and Linux.
● Python is open source
● Flexible programming styles: It supports object-oriented, and functional programming.
● Dynamic typing: You don’t need to declare the type of a variable; Python determines it
automatically.
Example:
<picture>
</picture>
5. Usage of alert() and prompt()
In JavaScript, alert() and prompt() are methods of window objects,used to interact with users via
pop-ups:
● alert():
It is the simplest dialogue box.Displays a simple pop-up message to the user. It is often used to show
notifications or warnings. The user can only close the pop-up by clicking "OK."
Example:
alert("Welcome to my website!");
This will display a message saying "Welcome to my website!" In a seperate small window box along
with a button OK.
● prompt():
The prompt dialogue box is also a method of window object. This method is used for getting an input
from the user,It displays a explorer user prompt dialogue box with a message and a input field.The
user can type a response, and the entered value is returned as a string.
Example:
If the user enters an vlaue it will be displayed in the webpage,if the user presses cancel,then the
value will be returned as null
● parseInt():
This function in javascript Converts a string into an integer by ignoring any decimal part. If the string
starts with non-numeric characters, it returns NaN.
Example:
● parseFloat():
This function Converts a string into a floating-point number, including decimals. Non-numeric
characters after the number are ignored.
Example:
LONG ANSWERS
2. <section>
The <section> tag groups related content together into logical sections, often under a heading.
It helps improve the structure of a webpage by dividing it into meaningful segments, making
the content easier to navigate.
Example:
<section>
<h2>About Our Services</h2>
<p>We specialize in creating user-friendly and responsive web designs.</p>
</section>
3. <article>
The <article> tag is used for self-contained content like blog posts, news articles, or
comments. Content within an <article> is meant to be reusable and can stand alone
independently.
Example:
<article>
<h3>How to Start Coding</h3>
<p>Learning to code begins with choosing the right language and practicing consistently.</p>
</article>
4. <footer>
The <footer> tag defines the bottom section of a webpage or a specific content block. It often
includes information like copyright notices, author details, or contact links.
Example:
<footer>
<p>© 2025 Natasha's Blog. All rights reserved.</p>
</footer>
5. <nav>
The <nav> tag is used to define a navigation section containing links to other parts of the
website or external resources. It helps improve accessibility and user experience by organizing
navigation menus.
Example:
<nav>
<ul>
<li><a href="#home">Home</a></li>
<li><a href="#about">About</a></li>
<li><a href="#services">Services</a></li>
</ul>
</nav>
6. <aside>
The <aside> tag is used for content that complements the main content, such as sidebars,
advertisements, or related links. It is typically displayed to the side of the main content.
Example:
<aside>
<h4>Related Articles</h4>
<ul>
<li><a href="#article1">5 Tips for Beginners</a></li>
<li><a href="#article2">Top 10 Coding Resources</a></li>
</ul>
</aside>
● Example:
Example:
let x = 5, y = 8;
console.log(x > y); // false
console.log(x === 5); // true
console.log(y !== 10); // true
● Logical Operators: These operators are used to combine multiple conditions or check logical
relationships. The main logical operators are:
o && (AND): Returns true if all conditions are true.
o || (OR): Returns true if at least one condition is true.
o ! (NOT): Reverses the boolean value.
Example:
● Assignment Operators: These are used to assign values to variables. The simplest assignment
operator is =. Other operators like +=, -=, *=, etc., modify the variable and assign the new
value in one step.
Example:
let z = 10;
z += 5; // z = z + 5 -> 15
z *= 2; // z = z * 2 -> 30
● String Operators: These operators are used to manipulate and combine strings. The most
common operator is the + operator for concatenation.
Example:
let firstName = "Natasha";
let lastName = "Nambiar";
let fullName = firstName + " " + lastName; // "Natasha Nambiar"
Operators in JavaScript are versatile tools that make programming logic and calculations more
efficient. They play a crucial role in building dynamic and functional web applications.
Example:
<!DOCTYPE html>
<html>
<head>
<title>Internal Script Example</title>
</head>
<body>
<h1>Welcome to My Website</h1>
<script>
alert("This is an internal script!");
</script>
</body>
</html>
While convenient, internal scripts can make the HTML file cluttered if there’s a lot of JavaScript code.
HTML File:
<!DOCTYPE html>
<html>
<head>
<title>External Script Example</title>
<script src="script.js"></script>
</head>
<body>
<h1>Welcome to My Website</h1>
</body>
</html>
External scripts allow developers to reuse the same JavaScript file across multiple HTML pages,
saving time and effort.
Example:
<!DOCTYPE html>
<html>
<head>
<title>Inline Script Example</title>
</head>
<body>
<button onclick="alert('Button Clicked!')">Click Me</button>
</body>
</html>
Inline scripts are best suited for small pieces of JavaScript code tied to specific elements.
Best Practices: For better maintainability and cleaner code, it’s recommended to use external scripts
for larger projects, while internal and inline scripts can be used for smaller, specific tasks.