0% found this document useful (0 votes)
8 views17 pages

Understanding JavaScript Basics and Features

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views17 pages

Understanding JavaScript Basics and Features

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

What is JavaScript?

JavaScript (JS) is a programming language that lets developers create interactive web pages.
JavaScript is a lightweight, object-oriented programming language that is used by several
websites for scripting web pages.

JavaScript is an interpreted language that executes code line by line, providing more flexibility.
It is a single-threaded language that executes one task at a time. JavaScript builds upon other
programming languages, updating them based on user interactions and other input.

Why learn JavaScript?

o Easy to Learn: JavaScript is beginner-friendly and easier to learn than many other
programming languages.
o Versatility: JavaScript can be used to develop websites, and you can use it on both the
server side and client side using Angular expressjs and [Link].
o Client Side: JavaScript is the main language for client-side logic and is supported by
almost all browsers. It also offers several frameworks and libraries such as ReactJS,
AngularJS, and js.
o Server Side: It is widely used for building server-side applications because it offers
runtime environments like [Link] and frameworks like [Link].
o Build Games: You can use JavaScript to create games, which can be 2D or 3D.

Features of JavaScript

There are many features of JavaScript, which are as follows:

Lightweight

JavaScript is a lightweight programming language that is made for handling data on the client
side. It has a minimal runtime and low resource requirements.

Dynamic Typing

JavaScript is a dynamic-typing language, which means variable types are specified on the basis
of the stored values. It means that developers don't need to specify the type of a variable before
assigning a data type to it.

Object-oriented programming

In JavaScript, object-oriented programming languages are similar to objects. It has methods and
properties that can be accessed and used in different ways. With the help of this feature,
developers can create the complex data structures and algorithms that are necessary for making
modern online apps.
Prototype Based

JavaScript is a prototype-based language, which means it utilizes prototypes in place of classes.


We can specify an object prototype, and after that, we can construct more objects with the help
of the specified object prototype.

Interpreted Language

JavaScript is an interpreted language, which means it executes the code line by line. A JavaScript
interpreter is a built-in feature that is provided by each browser and utilized to interpret the code.
JavaScript doesn't need to be compiled before it's used.

Application of JavaScript

There are multiple applications of JavaScript, some of them are as follows:

Web Development

JavaScript is integral to web development, playing a crucial role in creating responsive and
engaging websites. It works with HTML and CSS to add functionality and interactivity to web
pages. Many websites are made with the help of JavaScript, like Google, Facebook, Yahoo,
Twitter, Amazon, Wikipedia, LinkedIn, YouTube, etc.

Server Applications

JavaScript also helps users to create server-side applications. With the use of [Link] in
JavaScript, we can create server-side applications. Some of the big companies such as PayPal,
GoDaddy, etc., utilize [Link] for server apps.

Game Development

It also helps developers create games on the web. We use both HTML5 and JavaScript together
to develop games. With the help of libraries like Ease JS, developers can create an interactive
game for the web.

Web Applications

Web applications are created with the help of JavaScript. The frameworks of JavaScript, such
as Angular, React, etc., are utilized to build robust web apps.

Smartwatch Applications

Smartwatches are getting popular these days as they act as a substitute for mobiles. JS libraries
like Pebble are utilized for creating apps for smart watches.
Frameworks and Libraries of JavaScript

ReactJS => library


It is a popular JavaScript library that Meta and the community developed. The original author of
ReactJS was Jordan Walke. It is a free and open-source front-end JavaScript library, which
means anybody can utilize this framework without paying a single penny.

JQuery => framework


JQuery is one of the oldest frameworks of JavaScript. It was originally authorized by John Resig.
It is a free and open-source library that is used to create simple web applications. It helps
simplify HTML DOM elements, Ajax, CSS animations, and event handling.

[Link] => framework


[Link] is an open-source framework that is utilized to make user interfaces and single-page
applications. It was originally authorized by Evan You and was initially released in February
2014.

AngularJS => framework


AngularJS is a robust, free, and open-source JavaScript-based framework that Google developed.
AngularJS is used to simplify development and testing applications, and it is utilized as the front-
end of the MEAN stack.

[Link] => framework


[Link] is a fast and open-source backend web application framework that TJ Holowaychuk,
StrongLoop, and others developed. The main use of [Link] is to create complex web
applications and APIs. It has become the prime choice when using the Mean stack.

[Link] => framework


[Link] is an open-source framework that was initially released on December 8, 2011. It is used
to create scalable SPAs. It is used on various websites such as Nordstrom, HashiCrop, Apple
Music, Live Nation, Twitch, Intercom, Ghost, Square etc. With the use of this framework,
developers can create desktop and mobile applications.

JavaScript is one of the most popular programming languages, which includes several features
when it comes to web development. Some of its key features are lightweight, dynamic,
functional, and interpreted.

Important features of JavaScript:

1. Lightweight Scripting Language


2. Dynamic Typing
3. Functional Style
4. Platform Independent
5. Prototype-Based Language
6. Interpreted Language
7. Single-Threaded
8. Async Processing
9. Web Workers
10. Client-Side Validation
11. Backend Development
12. More Control in the Browser
13. Object-Oriented Programming
14. DOM Manipulation
15. Arrow Functions
16. Template Literal
17. Dynamic Import
18. Looping Statements
19. If Else Statement
20. Libraries and Frameworks
21. Control Statement
22. Event Handling
23. Date and Time Handling
24. HTML Content Generation
25. The Browser and OS Detection

1. Lightweight Scripting Language


JavaScript, which is a lightweight scripting language, is utilized for handling data on the client
side within the browser. The lightweight nature is a great feature of JavaScript because it is
meant for client-side execution for web applications.

2. Dynamic Typing
In JavaScript, dynamic typing is supported, which means types of the variable are defined based
on the stored value. In other words, you don't need to specify variable types; it will assign the
variable automatically at runtime.

Example: Suppose a variable named p is declared, then you store either a string, a number,
an array, or an object. It is known as dynamic typing.

3. Functional Style
A functional programming style is supported by JavaScript, where functions can be assigned to
variables, passed as arguments, and returned from other functions. JavaScript functions can be
used as objects and can be passed to other functions, too.

4. Platform Independent
JavaScript is a platform-independent language, or we can say it is portable, which means you can
simply write the script once and run it anywhere and anytime. With the use of JavaScript, you
can write your code for web applications and run them on any platform or any browser without
any issues with the output of JavaScript.

5. Prototype-based Language
JavaScript is a prototype-based language, which means it uses prototypes instead of classes or
inheritance. In class-based languages like Java, you first define a class and then create objects
from it. In JavaScript, instead of classes, objects can inherit directly from other objects through
prototypes.

6. Interpreted Language
JavaScript is an interpreted language, which means the script written in JavaScript is processed
line by line. The code is interpreted by a JavaScript interpreter, which is a built-in component of
the Web Browser.

7. Single-threaded
JavaScript is single-threaded by default. It does not support multi-threading, which means it only
executes a single task at a time.

JavaScript has some features that you can use to implement non-blocking execution. They are as
follows:

o Async Processing
o Web workers

8. Async Processing
JavaScript supports Promise, which enables asynchronous requests wherein a request is initiated
and JavaScript doesn't have to wait for the response. If a request takes more time, it may block
the request processing.

JavaScript Async functions are processed in parallel, not one by one, which has a positive effect
on the processing time, reducing it to a great extent.

9. Web Workers
In JavaScript, with the use of web workers, you can run processes in background threads so that
you can have parallel execution. In JavaScript, you have a task that performs some heavy-duty
work, and then you use web workers to run it in the background.

10. Client-Side Validations


JavaScript is used for implementing client-side validations. It is a feature that has been present in
JavaScript since the beginning, and it is used because every website has a form in which users
enter values, and to make sure that the users enter the correct value, we must use proper
validations on both the client-side and server-side.
11. Backend Development
By using JavaScript, backend development can also be done with [Link]. MERN stack is one of
the most popular stacks based on JavaScript for full-stack development.

There are many JavaScript Frameworks that are used in backend development. For
example, [Link] is used for API or REST service development, and [Link] includes npm,
which is a package manager for JavaScript modules, which means you can use third-party
packages too, which makes backend development more fun and easy.

12. More Control in Browser


JavaScript is a client-side language that provides many features that help developers, so they can
divide the processing between the browsers and the server, which reduces the load on the server
by having basic processing, validations, and temporary data saving using cookies, etc., on the
browser itself.

13. Object-Oriented Programming (OOP)


In JavaScript, object-oriented programming is a way of writing code. It utilizes classes and
objects to model real-world things like data and behaviour. A class in JavaScript is a blueprint
that defines the methods and properties an object possesses. An object is an instance of a class.

14. DOM Manipulation


In JavaScript, DOM Manipulation is a technique that is very useful for changing the content and
the style of a web page. By utilizing DOM, the developer is able to access the content of the html
page and change it dynamically. The use of DOM in JavaScript is very useful for developing an
interactive website.

15. Arrow Functions


Arrow functions were introduced in ES6 of JavaScript, and they provide a more concise syntax
for defining function expressions in JavaScript. They are useful for a single-expression function.
They are also typically referred to as fat arrow functions. Arrow functions also have lexical
scoping for this keyword, which eliminates many of the simple bugs associated with it. They
thus make code simpler, which makes it easier to read and maintain.

16. Template Literal:


In JavaScript, template literals can be utilized to compose strings that include variables and
expressions. Instead of using double or single quotes to define strings, we define template literals
with backticks (`) around the string and then insert expressions or variables inside curly brackets
${}.

We can then build longer and more complex strings more comfortably, and it allows us to write
less wordy code, because template literals use multi-line support.

17. Dynamic Import:


Dynamic import, which uses the import () syntax, is a basic functionality of JavaScript. This
allows code splitting and lazy loading of modules, allowing for parts of the code base to be
loaded as needed, thereby improving the initial load time and overall performance. Dynamic
imports become more useful in larger applications when all of the functionalities are not going to
be needed right away, which allows for more efficient usage of resources.

18. Looping Statements:


JavaScript supports various forms of looping statements, including for loops, while loops, do
while loops, etc. It is extremely useful when we want to run a chunk of code a number of times.
The Looping statement is critical in terms of organizing tasks, from manipulating arrays to
traversing and manipulating the DOM. JavaScript looping statements help to manage large data
sets or times when we accomplish the same tasks repeatedly, contributing to the overall
versatility of the language in developing complex applications.

19. If-else Statement:


In JavaScript, we can utilize if-else statements, which allow us to control the flow of our code
based on a condition. If a condition is evaluated as either true or false, different parts of the code
are executed. This fundamental control structure allows us to enable logic-driven applications
and decision-making in our applications, which is ideally suited for constructing dynamic,
interactive web pages.

20. Libraries and Frameworks


The JavaScript ecosystem is massive, consisting of libraries and frameworks that strengthen and
extend JavaScript's capabilities. These libraries and frameworks provide pre-existing code,
functions, and tools to help facilitate the rapid, efficient, and organized development of modern
web applications.

21. Control Statement


Control statements such as if-else, while, and for are control flow statements used for controlling
the execution of the code in JavaScript. These statements allow the code to make decisions based
on conditional execution, and to repeat actions. Control statements are an important part that is
utilized for creating more complex functionality and logic in web applications.

22. Event Handling


One of JavaScript's best features is event handling. It provides the ability for the web page to
respond and react whenever the user takes action or something else happens. In the context of the
browser, user actions (e.g., mouse clicks, key presses, etc.) are events. By taking advantage of
the event listener feature, JavaScript can run a piece of code whenever an event happens. This
allows for updates in real time and interactive functionality in webpages.

23. Date and Time Handling:


JavaScript has objects and functions for processing dates and times. They are built-in. The built-
in Date object primarily handles this. It allows for timers, calendars, and scheduling without the
need for server-side processing. These abilities allow for "real-time" and dynamic features (such
as countdowns and time-based actions), which improve user engagement and interaction.
24. HTML Content Generation
JavaScript allows us to create and modify HTML content dynamically and directly in the
browser. We can use methods like innerHTML, createElement, or appendChild to add,
modify, or remove elements and content. This is a very important action when we are developing
dynamic web applications, when we need to modify or create content based on user events or
live data.

25. The Browser and OS Detection


By using JavaScript, we can determine the browser and operating system a user is utilizing. This
gives developers the ability to customize the experience, optimize performance, or route users to
different versions of a website or application based on the user's operating system and browser.
While feature detection is typically favored over browser detection, knowing the browser and
operating system may be useful for debugging purposes or analytics files.
Difference Between Java and JavaScript
Java is an OOP programming language, while JavaScript is an OOP scripting language. Java is
used to create applications that run in a virtual machine or browser, while JavaScript code runs
on a browser only.

Though both are programming or scripting languages used by programmers for a variety of
tasks, their similarities end with Java. In this tutorial, we will see the difference between Java
and JavaScript.

What is Java?

Java is a programming language and a platform. Java is a high-level, robust, object-oriented and
secure programming language. Java is utilised as a computing platform and was developed by
Sun Microsystems in the year 1995.

Example
//Simple program to print Hello World in Java
public class main
{
public static void main(String args[])
{
[Link]("Hello, World!");
}
}

What is JavaScript?

JavaScript is a scripting language that is object-based and helps to create interactive web pages.
It is a single-threaded language that executes one task at a time.

JavaScript, originally developed by Brendan Eich at Netscape in 1995, was designed to add
interactivity to web pages and evolved into a powerful language that is used for both front-end
and back-end web development.

Example
//Simple program to print Hello World in JavaScript
[Link]("Hello, World!");
Difference Between Java and JavaScript

Java Language JavaScript Language

It is a programming language. It is a scripting language.

Java is a pure object-oriented programming JavaScript is an Object-Based Language.


Language.

Java is a Standalone language. JavaScript is not a standalone language, as it needs to


be integrated into an HTML program for execution.

Java is a strongly typed language, which JavaScript is a loosely typed language, which means
means that the user has to decide the data that the user does not have to worry about the data type
type of the variable before declaring and of the variable before and after the declaration.
using it. Example "var a", the "a" variable can store the value of
Example "int a", the variable "a" can store the any data type.
value of an integer type only.

A Java program should be compiled before JavaScript needs to be integrated into the HTML
execution. program for execution.

The web browser is not required to run Java A web browser is essential to run the JavaScript
programs. program.

It is one of the complex languages to learn. It is one of the easiest languages to learn.

In Java, by utilizing Multi-threading, users In JavaScript, a user is not able to perform complicated
can perform complicated tasks. tasks.

It requires a large amount of memory. It does not require that amount of memory.

Sun Microsystems developed the Java Netscape developed the JavaScript programming
programming language." language."

In the Java programming language, programs In JavaScript, programs can be saved using the .js
are saved with the ".java" extension. extension.

Java is stored on the host machine as the JavaScript is stored on the Host machine(client-side) as
"Byte" code. the source text.

Java code runs on the Java Virtual Machine JavaScript runs directly in the browser's environment,
(JVM), which allows it to be platform- mainly used for client-side web development.
independent.

Java supports multithreading, allowing JavaScript uses event-driven, single-threaded


concurrent execution of two or more parts of architecture but supports asynchronous behavior via
a program for maximum CPU utilization. callbacks, promises, and async/await.

Java has rich APIs for networking, file JavaScript mainly interacts with the DOM, HTML, and
handling, database connection (JDBC), etc. CSS, and accesses data from APIs via AJAX/fetch.

Java supports static typing, where variable JavaScript supports dynamic typing, where variable
types are declared explicitly. types are determined at runtime.

Java supports inheritance through classes and JavaScript supports prototypal inheritance.
interfaces.

Java can be used to build standalone JavaScript is mainly used for frontend development,
applications, enterprise-level backend though it can be used for backend development via
systems, Android apps, and more. [Link].

Java programs are typically heavier and more JavaScript programs are generally lightweight and
resource-intensive. optimised for performance in browsers.

Java has built-in exception handling with try- JavaScript has exception handling as well, but it is less
catch-finally and custom exceptions. robust and more prone to runtime errors.

Java uses OOP concepts like Encapsulation, JavaScript has some OOP features, but it is more
Abstraction, Inheritance, and Polymorphism functional and event-driven.
extensively.
Java requires a development environment like JavaScript code can be written and run using a simple
Eclipse, IntelliJ, or NetBeans. text editor and browser console.
JavaScript Syntax

Introduction

JavaScript syntax dictates the rules of writing valid code similar to C and Java. In simple words,
JavaScript syntax refers to the rules and conventions dictating how code is structured and
arranged within the JavaScript programming language. It is case sensitive, uses semicolons to
terminate statements, and employs curly braces to define code blocks.

Syntax
The syntax of JavaScript is as follows:

[Link]("Welcome to JavaScript World");


JavaScript Values
The JavaScript syntax defines two types of values:

o Fixed values: The fixed values are known as literals.


o Variable values: The variable values are called variables.

JavaScript Literals

JavaScript syntax rules for fixed values are:

In JavaScript, numbers can be written with or without decimals.

Example
let a = 10
let b = 11.05
[Link](a);
[Link](b);

In JavaScript, strings are text that can be written with single or double quotes.

Example
let str = 'welcome'
let str1 = 'JS World'
[Link](str);
[Link](str1);
JavaScript Variables

A JavaScript variable is a named storage location that holds a value, which can be any data type,
such as numbers, strings, objects, etc. It can be declared using keywords like var, let, or const.

There are two types of variables in JavaScript, such as:

Local variable: In JavaScript, local variables are declared inside a block or a function.

Global variable: In JavaScript, global variables are declared outside a function or with a
window object.

Example
let word = "RamTech";
function myFunction(){
let a = 20;
[Link](word);
[Link](a);
}
myFunction();

JavaScript Operators

JavaScript operators are symbols that operate on one or more operands to produce a result.
Arithmetic operators (+,-, *, /) are used to compute the value, and Assignment operators (=) are
used to assign the values to variables.

Example
let a, b, div;
a = 10;
b = 5;
div = a/b;
[Link](div);

JavaScript Expression

In JavaScript, an expression is a combination of values, operators, and variables. JavaScript


expressions are used to compute the values.

Example
let a, b, sub, div;
a = 10;
b = 5;
//expression to subtract two numbers
sub = a - b;
//expression to divide a number
div = a/b;
[Link](sub);
[Link](div);

JavaScript Keywords

JavaScript contains multiple keywords that can be used for a particular task. For example, the
function keywords can be used to define the function. You can use let, var, and const keywords
to define the variables.

Example
function getSum(a,b)
{
var sum = a * b;
[Link]("The product of " + a + " and " + b + " is "+ sum);
}
let a = 5;
let b = 10;
getSum(a, b);

JavaScript Comments

In JavaScript, comments are ignored by the JavaScript compiler. Comments increase the
readability of code. It adds suggestions, information, and warnings about code.

There are two primary types of codes in JavaScript:

Single-line comments: These comments begin with // and continue to the end of the line.

//This is a single-line comment


let a = 5; //initialize a to 5
Multi-line comments: These comments are enclosed between /* and */ and can span multiple
lines.

/* This is a multi-line comment


Welcome to TpointTech */
let a = 5;

JavaScript Data Types

In JavaScript, we have different data types that hold different values or variables. JavaScript is a
dynamic programming language, which means we do not need to specify the type of variable.

There are two types of data types present in JavaScript:

• Primitive data types


• Non-primitive data types

Example
// it stores a string data type
let str = "RamTech";
//it stores an integer data type
let a = 10;
//it stores Boolean data type
(a == b)
// it stores array data type
let fruits = ["Apple", "Orange", "Banana"];
//it store object data
let study = {
firstName: "John",
lastName: "Miller",
age: 24,
mark: "redEye"
}

JavaScript Functions

In JavaScript, a function is a reusable block of code used to perform certain operations.


The JavaScript function is executed when something calls it.

Syntax

function functionName(parameters)
{
//code to be executed
}

Example
function myDemo()
{
let a = 9;
let b = 1;
let sum = a + b;
[Link](sum);
}
myDemo();
JavaScript Identifier

JavaScript identifiers are names that are used to name variables and keywords, or functions. In
JavaScript, an identifier must begin with:

• A letter (A-Z to a-z)


• A dollar sign($)
• A underscore(_)

JavaScript Camel Case

In JavaScript, Camel case is preferred to name an identifier.

Example
let firstName
let rollNo

JavaScript Character Set

JavaScript contains a set of Unicode characters. The Unicode characters add special characters
like emoji, symbols, etc., to the text. Unicode covers almost all the characters, punctuations, and
symbols in the world.

You might also like