Ethio-Parents' School: Ict Project: Javascript
Ethio-Parents' School: Ict Project: Javascript
MEMBERS
1. Dagmawi Belayneh
2. Hikma Yasin
3. Hasset Adugna
4. Haroni Abush
5. Mihret Sisay
6. Biruk Yenew
May 2024
JAVASCRIPT
1.1 Introduction
Background of JavaScript
JavaScript, often abbreviated as JS, is a high-level, interpreted programming language that is
widely used for web development. Developed by Brendan Eich in 1995, JavaScript was
originally created to enhance the interactivity of websites by allowing client-side scripts to
interact with the user interface. Over the years, JavaScript has evolved into a versatile language
that can be used for both front-end and back-end development.
Evolution of JavaScript
In November 1996, Netscape submitted JavaScript to Ecma International, as the starting point
for a standard specification that all browser vendors could conform to. This led to the official
release of the first ECMAScript language specification in June 1997. The standards process
continued for a few years, with the release of ECMAScript 2 in June 1998 and ECMAScript 3
in December 1999. Work on ECMAScript 4 began in 2000.
However, the effort to fully standardize the language was undermined by Microsoft gaining an
increasingly dominant position in the browser market. By the early 2000s, Internet Explorer's
market share reached 95%. This meant that JScript became the de facto standard for client-side
scripting on the Web.
Microsoft initially participated in the standards process and implemented some proposals in its
JScript language, but eventually it stopped collaborating on ECMA work. Thus ECMAScript 4
was mothballed.
Importance in Web Development
JavaScript plays a vital role in modern web development, enabling developers to create
dynamic and interactive websites. From form validation to animations and real-time updates,
JavaScript allows for seamless user experiences on the web. With the rise of single-page
applications (SPAs) and server-side JavaScript frameworks like Node.js, the importance of
JavaScript in web development continues to grow.
The use of JavaScript has expanded beyond its web browser roots. JavaScript engines are now
embedded in a variety of other software systems, both for server-side website deployments and
non-browser applications. Initial attempts at promoting server-side JavaScript usage were
Netscape Enterprise Server and Microsoft's Internet Information Services, but they were small
niches.
Server-side usage eventually started to grow in the late 2000s, with the creation of Node.js and
other approaches. Electron, Cordova, React Native, and other application frameworks have
been used to create many applications with behavior implemented in JavaScript. Other non-
browser applications include Adobe Acrobat support for scripting PDF documents and
GNOME Shell extensions written in JavaScript. JavaScript has recently begun to appear in
some embedded systems, usually by leveraging Node.js.
// The keyword `const` means constant, hence the variable cannot be reassigned
// as the value is `constant`.
const z = "this value cannot be reassigned!";
// Declares a variable named `myNumber`, and assigns a number literal (the value
// `2`) to it.
let myNumber = 2;
Note the comments in the examples above, all of which were preceded with two forward
slashes.
There is no built-in Input/output functionality in JavaScript, instead it is provided by the run-
time environment. The ECMAScript specification in edition 5.1 mentions that "there are no
provisions in this specification for input of external data or output of computed results".
However, most runtime environments have a console object that can be used to print output.
Here is a minimalist "Hello, World!" program in JavaScript in a runtime environment with a
console object:
Example: console.log("Hello, World!");
// Arithmetic operations
let x = 10;
let y = 5;
let sum = x + y;
let product = x * y;
// Comparison operators
let isEqual = x === y;
let isGreaterThan = x > y;
// Logical operators
let isTrue = true;
let isFalse = false;
let result = isTrue && isFalse; // false
Declaring Functions
Functions in JavaScript can be declared using the function keyword followed by a function
name and optional parameters enclosed in parentheses. Functions can have return values and
can be invoked multiple times within a script.
Almost every time you use a JavaScript statement with parentheses, you are simply making use
of a JavaScript function. Functions fall into the JavaScript data type called objects and almost
every JavaScript program runs inside a function.
Functions in JavaScript are very similar to those of some other scripting high-level languages
such as TypeScript and there are two types of functions: predefined and user defined. The
predefined functions are functions that are built-in, already embedded in the program while the
user-defined function which is the focus of this article are functions that a user inputs into the
program to perform custom tasks.
In JavaScript, there are different ways of declaring functions. Let’s examine what a
function declaration is.
A function declaration, also known as function definition or statement, is a way of
providing sets of instructions to be carried out in a program when executed. It is a way of
saving a function with a particular parameter so it can be called (invoked) when needed
to perform the task for which it was defined.
The syntax (as seen below) of a function must be defined before it can be implemented:
1. function name() {
2. // .......
3. }
Return Statements
The return statement in a function specifies the value that the function should return when it is
called. Functions can return values of any data type or even other functions.
Creating Objects
Objects in JavaScript are collections of key-value pairs known as properties. Objects can
contain methods (functions) that operate on their properties.
Array Methods
JavaScript provides built-in array methods like push, pop, shift, unshift, map, filter, reduce, and
for. Each for performing common operations on arrays efficiently.
Selecting Elements
JavaScript provides methods like getElementById, getElementsByClassName, querySelector,
querySelectorAll, etc., for selecting elements from the DOM based on various criteria.
Event Handling
Events like click, hover, submit, keypress, etc., can be handled using event listeners in
JavaScript. Event handlers can be attached to elements to trigger specific actions in response to
user interactions.
Callback Functions
Callback functions are functions passed as arguments to other functions and executed
asynchronously when a specific event occurs, or an operation completes. A callback is a
function passed as an argument to another function. This technique allows a function to call
another function. A callback function can run after another function has finished.
Promises
Promises are objects representing the eventual completion (or failure) of an asynchronous
operation and allow chaining multiple asynchronous operations sequentially. A Promise is a
proxy for a value not necessarily known when the promise is created. It allows you to associate
handlers with an asynchronous action's eventual success value or failure reason. This lets
asynchronous methods return values like synchronous methods: instead of immediately
returning the final value, the asynchronous method returns a promise to supply the value at
some point in the future.
Async/Await
Async/Await is a modern approach to handling asynchronous code in JavaScript using async
functions and await expressions to simplify asynchronous programming and make it more
readable.
Fetch API
The Fetch API is a modern replacement for XMLHttpRequest that provides a simpler interface
for making network requests in JavaScript using promises.
Types of Errors
JavaScript errors can be categorized into syntax errors (parsing errors), runtime errors
(exceptions), and logical errors (bugs). Understanding the types of errors is essential for
effective error handling. There are 7 types of JavaScript errors: Syntax error, Reference Error,
Type Error, Evaluation Error, RangeError, URI Error and Internal Error.
Syntax error - The error occurs when you use a predefined syntax incorrectly.
Reference Error - In a case where a variable reference can't be found or hasn't been
declared, then a Reference error occurs.
Type Error - An error occurs when a value is used outside the scope of its data type.
Evaluation Error - Current JavaScript engines and ECMAScript specifications do not
throw this error. However, it is still available for backward compatibility.
URI Error - When the wrong character(s) are used in a URI function.
Internal Error - In the JS engine, this error occurs most often when there is too much
data, and the stack exceeds its critical size. When there are too many recursion patterns,
switch cases, etc., the JS engine gets overwhelmed.
Try-Catch Blocks
Try-Catch blocks allow developers to catch exceptions thrown during execution and handle
them gracefully without causing the script to crash.
Error Objects
JavaScript provides built-in error objects like SyntaxError, ReferenceError, TypeError, etc.,
which can be used to identify specific types of errors in code.
Prototypal Inheritance
JavaScript uses prototypal inheritance where objects inherit properties from other objects
through prototype chains rather than classes like in traditional object-oriented languages.
Prototype inheritance in JavaScript is the linking of prototypes of a parent object to a child
object to share and utilize the properties of a parent class using a child class. Prototypes are
hidden objects that are used to share the properties and methods of a parent class with child
classes.
Security Considerations
Preventing common security vulnerabilities like cross-site scripting (XSS), cross-site request
forgery (CSRF), injection attacks require implementing secure coding practices such as input
validation, output encoding, authentication mechanisms, etc.
behavior of an HTML page. This allows you to create interactive web applications, implement
dynamic user interfaces, and perform various operations on the document based on user actions
or programmatic logic.
1.15 Conclusion
Summary of Key Points
In conclusion, this comprehensive project has covered a wide array of topics related to
JavaScript programming—from basic syntax to advanced concepts—in an effort to equip
readers with the knowledge and skills necessary to excel in web development using JavaScript.
REFERENCES
Geeksforgeeks.org
Medium.com
Wikipedia.com
Midjourney chatbot ai