WHAT IS JAVA SCRIPT?

JavaScript is a text-based programming language used both on the client-side and server-side that allows you to make web pages interactive. Where HTML and CSS are languages that give structure and style to web pages, JavaScript gives web pages interactive elements that engage a user.In web browsers, JavaScript consists of three main parts:

 ECMA Script provides the core functionality.

 The Document Object Model (DOM) provides interfaces for interacting with elements on web pages

 The Browser Object Model (BOM) provides the browser API for interacting with the web browser.

 JavaScript allows you to add interactivity to a web page. JavaScript is often used with HTML and CSS to enhance a web page’s functionality, such as validating forms, creating interactive maps, and displaying animated charts.

When a web page is loaded, i.e., after HTML and CSS have been downloaded, the JavaScript engine in the web browser executes the JavaScript code. The JavaScript code then modifies the HTML and CSS to update the user interface dynamically.

  WHAT IS JAVA SCRIPT USED FOR ?

JavaScript is used in every industry to create all types of applications. Let's take a closer look at its uses in web development, mobile development, game development, and more.Some examples are below

1. Adding interactive behavior to web pages.


JavaScript allows users to interact with web pages. There are almost no limits to the things you can do with JavaScript on a web page – these are just a few examples:

2. Creating web and mobile apps

Developers can use various JavaScript frameworks for developing and building web and mobile apps. JavaScript frameworks are collections of JavaScript code libraries that provide developers with pre-written code to use for routine programming features and tasks—literally a framework to build websites or web applications around.
Popular JavaScript front-end frameworks include React, React Native, Angular, and Vue. Many companies use Node.js, a JavaScript runtime environment built on Google Chrome’s JavaScript V8 engine. A few famous examples include Paypal, LinkedIn, Netflix, and Uber!

3. Building web servers and developing server applications

Beyond websites and apps, developers can also use JavaScript to build simple web servers and develop the back-end infrastructure using Node.js.

4. Game development

Of course, you can also use JavaScript to create browser games. These are a great way for beginning developers to practice their JavaScript skills.


 Why use JavaScript over other languages?

Aside from the unlimited possibilities, there are many reasons for web developers to use JavaScript over other programming languages:


  How is JavaScript different from Java?

JavaScript does not create applets or stand-alone applications. In its most common form, JavaScript resides inside HTML documents, and can provide levels of interactivity to web pages that are not achievable with simple HTML.

Difference between Java and JavaScript

 EXPLANATION IN THE VIDEO BELOW




 DISPLAYING A MESSAGE IN JAVA SCRIPT

There are four ways to display text in the browser using JavaScript:

 JAVASCRIPT VARIABLES

Like many other programming languages, JavaScript has variables. Variables can be thought of as named containers. You can place data into these containers and then refer to the data simply by naming the container. Before you use a variable in a JavaScript program, you must declare it.
There are 3 ways to declare a JavaScript variable:

  Using var
  Using let
  Using const

PRACTICAL EXPLANATION IN THE VIDEO


 DECISION MAKING IN JAVA SCRIPT

Conditional statements are used to perform different actions based on different conditions.Very often when you write code, you want to perform different actions for different decisions.You can use conditional statements in your code to do this.

In JavaScript we have the following conditional statements:


 IF STATEMENT IN JAVA SCRIPT

The if statement is the fundamental control statement that allows JavaScript to make
decisions and execute statements conditionally. Here a JavaScript expression is evaluated. If the resulting value is true, the given statement(s) are executed. If the expression is false, then no statement would be not executed. Most of the times, you will use comparison operators while making decisions.

SYNTAX 

if (expression) {
Statement(s) to be executed if expression is true
}

IF ELSE STATEMENT IN JAVA SCRIPT

The 'if...else' statement is the next form of control statement that allows JavaScript to execute statements in a more controlled way.

SYNTAX 

if (condition) {
statement1
}
else {
statement2
}

Here JavaScript expression is evaluated. If the resulting value is true, the given statement(s) in the ‘if’ block, are executed. If the expression is false, then the given statement(s) in the else block are executed.

PRACTICAL EXAMPLE IN THE VIDEO



 JavaScript Switch Statement

The switch statement is used to perform different actions based on different conditions
Use the switch statement to select one of many code blocks to be executed.

SYNTAX 

switch(expression) {
case x:
// code block
break;
case y:
// code block
break;
default:
// code block }

This is how it works 

Example

The getDay() method returns the weekday as a number between 0 and 6.
(Sunday=0, Monday=1, Tuesday=2 ..)
This example uses the weekday number to calculate the weekday name:
switch (new Date().getDay()) {
case 0:
day = "Sunday";
break;
case 1:
day = "Monday";
break;
case 2:
day = "Tuesday";
break;
case 3:
day = "Wednesday";
break;
case 4:
day = "Thursday";
break;
case 5:
day = "Friday";
break;
case 6:
day = "Saturday";
}

PRACTICAL EXAMPLE IN THE VIDEO