Java Script
JavaScript is developed by Brendan Eich, who was a Netscape programmer.JavaScript is a scripting language that is object-based, lightweight, cross-platform translated language. It is widely used for client-side validation.
features of JavaScript are:
- Lightweight
- Interpreted programming language
- Good for the applications which are network-centric
- Complementary to Java
- Complementary to HTML
- Open source
- Cross-platform
Some of the advantages of JavaScript are erver interaction is less,feedback to the visitors is immediate, interactivity is high, interfaces are richer.
Disadvantages are no support for multithreading, no support for multiprocessing,reading and writing of files is not allowed, and no support for networking applications.
Type of java script functions;
- Named functions contains name at the time of definition.
- Anonymous functions doesn't contain any name. They are declared dynamically at runtime.
JavaScript variables can belong to the local or global scope.Global variables can be made local (private) with closures.
3 places where we can put javascript code
- Between the body tag of html
- Between the head tag of html
- In .js file (external javaScript)
key differences between Java and JavaScript?
Java is a complete and strongly typed programming language used for backend coding. In Java, variables must be declared first to use in the program, and the type of a variable is checked at compile-time where as JavaScript is a weakly typed, lightweight programming language (most commonly known as scripting language) and has more relaxed syntax and rules.
Java is an object-oriented programming (OOPS) language or structured programming languages such as C, C++, or .Net while JavaScript is a client-side scripting language, and it doesn't fully support the OOPS concept. It resides inside the HTML documents and is used to make web pages interactive.
Java programs consume more memory.JavaScript code is used in HTML web pages and requires less memory.
Java is a Complete and Standalone language that can be used in backend coding.JavaScript is assigned within a web page and integrates with its HTML content.
Java supports multithreading.JavaScript doesn't support multithreading.
Java uses a thread-based approach to concurrency.JavaScript uses an event-based approach to concurrency.
JavaScript is a case sensitive language
BOM: BOM(Browser object model) provides interaction with the browser. The default object of a browser is a window.
Window object is created automatically by the browser that represents a window of a browser. It is not an object of JavaScript. It is a browser object and used to display the popup dialog box.
History object of a browser can be used to switch to history pages such as back and forward from the current page or another page.
There are two types of data types in JavaScript:
- Primitive data types - primitive data types can store only a single value. Eg: Symbol, null, undefine, Strin, BigInt, Boolean, Number
- Non- Primitive data types - To store multiple and complex values, we have to use non-primitive data types.Eg: Object, Array
The == operator checks equality only whereas === checks equality, and data type.
JavaScript object creation
- By Object literal
<script>
emp={id:102,name:"Shyam Kumar",salary:40000}
document.write(emp.id+" "+emp.name+" "+emp.salary);
</script>
- Creating instance of object
var objectname=new Object();
- Using Object constructor
<script>
function emp(id,name,salary){
this.id=id;
this.name=name;
this.salary=salary;
}
e=new emp(103,"Vimal Jaiswal",30000);
</script>
There are 3 ways to create an array in JavaScript.
- By array literal - var arrayname=[value1,value2.....valueN];
- By creating an instance of Array - var arrayname=new Array();
- By using an Array constructor -
Comments
Post a Comment