JSON - SPLessons
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

JSON JavaScript

JSON JavaScript

shape Description

Before learning JSON, it's better to learn JavaScript language. JavaScript is a lightweight scripting language used to create network-based applications. It is very easy to implement as it is integrated with Java and HTML programming languages. JavaScript is an open and cross-platform programming language that involves both functional programming and object-oriented features. JavaScript can integrate with Java and HTML, but, it is not an extension to Java. Simply put, JavaScript is a language that can be understood by the browser and defines the behavior of web pages. The functionality of web pages mainly depends on 3 things. While learning any languages it's better to learn OOPS concepts.

Inheritance

An inheritance is nothing but acquiring the properties from the previous class.

Abstraction

Hiding the class implementation details is known as abstraction. Abstraction can be achieved by defining class behavior in an interface and implementing it in a class. Instead of creating a class reference, referring to the class object through an interface reference is known as abstraction. The advantage of abstraction is if the implementation of the class is changed, that will not affect the usage of the class, hence one can provide enhancement modification easily.

Polymorphism

polymorphism is the OOPS concept that means one can perform a single action by various ways, actually poly means many and morph means forms, these both words are Greek words. There are two types of polymorphism, one is compile time polymorphism and the second one is a runtime polymorphism. By using method overloading and method overriding developer can perform polymorphism.

Encapsulation

Encapsulation is a process of protecting the members of the class. Java has completely encapsulated body which protects a member by using access specifiers. The best example is Java Bean Class. Developing a Java class with the private fields and providing access to the private fields using getters and setter method known as a Java Bean Class.

Syntax For JavaScript

shape Syntax

The JavaScript Syntax is as follows: [html] <script> Javascript code </script> [/html] Following is the JavaScript Syntax for placing script tags inside HTML tags. [html] <!DOCTYPE html> <html> <head> <title>Script Sample</title> <script charset="UTF-8" type="text/javascript"> Alert("Hello World"); </script> </head> <body> <h1>Welcome to SPLesson</h1> </body> </html> [/html] Following is the description for the above example.

JavaScript Variables and Data Types

shape Description

JavaScript Variables can be used to store, retrieve and manipulate the values present in the code. So, they must be given meaningful names to make the user easily understand the function of the code. Following examples illustrate the declaration of variables. [html] var age; //age variable declared var age,date,amount; // age,date,amount variables are created var age=24,date="16/6/2020", amount=20000; //variable age is assigned value 24,date assigned 16/6/2020 value and amount given 20000 value. [/html] JavaScript is a dynamic scripting language, which can assign the data type to a variable dynamically. This interpretation of data type to a variable is done by JavaScript script engine. Now, let's take a look at various JavaScript DataTypes. Composite Datatypes are important in JavaScript functioning and are also called as non-primitive datatypes. They are classified into 3 types, such as:

shape Example

Following is an example for the form validation. When the form is submitted without providing the data in the form field, JavaScript will show a pop-up message restricting the form submission. The syntax for JavaScript Forms function is as follows. [html]validateForm()[/html] The function will be as follows: [html]Function validateForm() { Var x = document.forms[“testForm”][“firstname”].value; If (x == null || x ==” “) { alert(“Please Enter your first name”); return false; } }[/html] Following is the source code for the form validation. [html]<!DOCTYPE html> <html> <head> <script> Function validateForm() { Var x = document.forms["testForm"]["firstname"].value; If (x == null || x ==" ") { alert("Please Enter your first name"); return false; } } </script> </head> <body> <form name="testform" action="testform.asp" onsubmit="returnvalidateForm()" method="post"> First name: <input type="text" name="firstname"> <input type="submit" value="Submit"> </form> </body> </html>[/html] In the above example, action = “testform.asp” and method = “post” sections depends on form action types and submission methods that are used by the server. Output: Now compile the code result will be as follows.

Summary

shape Key Points

  • JavaScript Forms Validation can be done on both server and client side.
  • JavaScript Forms Authentication is helpful in securing the user’s data.
  • JavaScript Popup boxes are used to convey the important messages and alerts to the user.
  • Pop-up window opens the pop-up in a new window using window.open() method.
  • Global variables can be declared and accessed anywhere.