Javascript Notes
JavaScript
Data Types
Variables
Operators
Functions
Conditional Statements and Loops
Arrays
Objects
DOM Elements
Cookies
Pop Up Box
Exception Handling
Heading
Q
1
What is JavaScript?
Ans
JavaScript is a scripting or programming language that allows you to implement complex features on web pages. Every time a web page does more than just sit there and display static information for you to look at. displaying timely content updates, interactive maps, animated 2D/3D graphics, scrolling video jukeboxes, etc.
Q
2
List out the features of JavaScript.
Ans
JavaScript is one of the most popular languages which includes numerous features when it comes to web development. It's amongst the top programming languages as per Github and we must know the features of JavaScript properly to understand what it is capable of.
Some of the features are lightweight, dynamic, functional and interpreted. Now we are going to discuss some important features of JavaScript.
1.Light Weight Scripting language
2.Dynamic Typing
3. Object-oriented programming support
4. Functional Style
5.Platform Independent
6. Prototype-based
7.Interpreted Language
8. Async Processing
9. Client-Side Validation
10. More control in the browser
Q
3
Why is JavaScript important in web design?
Ans
JavaScript (JS) is very popular and adopted universally by every web browser for its support which allows dynamic content to get executed in a webpage. It's an object scripting language which is used in web pages along with markup language HTML. JavaScript does not incorporate or abide by any HTML tags or rules. It is similar to the stand-alone programming language developed by Sun Microsystems. JavaScript got its success worldwide with its integration into the web browsers. JS stands unique as it brings out all the special functionalities in the client’s browser instead of the site’s server.
JavaScript can make the website more interactive and user-friendliness of JavaScript helps easy navigation of the website and helps designers to guide the visitors with additional information or guide them through walkthroughs. Visual effects can also be achieved with JavaScript. JavaScript can be used effectively to create special effects like rollover for images.
Q
4
Define JavaScript statement.
Ans
JavaScript statements are composed of:
Values, Operators, Expressions, Keywords, and Comments.
This statement tells the browser to write "Hello Dolly." inside an HTML element with id="demo":
Example
document.getElementById("demo").innerHTML = "Hello Dolly.";
Most JavaScript programs contain many JavaScript statements.
The statements are executed, one by one, in the same order as they are written.
JavaScript programs (and JavaScript statements) are often called JavaScript code.
Q
5
Write a note on Comments in JavaScript.
Ans
JavaScript comments can be used to explain JavaScript code, and to make it more readable.
JavaScript comments can also be used to prevent execution, when testing alternative code.
Single Line Comments
Single line comments start with //.
Any text between // and the end of the line will be ignored by JavaScript (will not be executed).
This example uses a single-line comment before each code line:
Example
// Change heading:
document.getElementById("myH").innerHTML = "My First Page";
// Change paragraph:
This example uses a single line comment at the end of each line to explain the code:
Example
let x = 5; // Declare x, give it the value of 5
let y = x + 2; // Declare y, give it the value of x + 2
Multi-line Comments
Multi-line comments start with /* and end with */.
Any text between /* and */ will be ignored by JavaScript.
This example uses a multi-line comment (a comment block) to explain the code:
Example
/*
The code below will change
the heading with id = "myH"
and the paragraph with id = "myP"
in my web page:
*/
document.getElementById("myH").innerHTML = "My First Page";
document.getElementById("myP").innerHTML = "My first paragraph.";