Errors – JavaScript Basics

try statement allows to analyse block of code for errors. catch statement allows to handle error. throw statement allows to create custom errors. finally statement allows to carry out code, after try & catch, regardless of result. Try and Catch JS statements try and catch come in pairs. try {     Block of code to try } catch(err) {     Block of code to handle

Continue reading Errors – JavaScript Basics

Switch Statement – JavaScript Basics

It is used to perform different actions on different conditions. How does it works?? – switch expression is classified once & value of expression is compared with values of each case. The associated block of code is executed if there’s a match. <!DOCTYPE html> <html> <body> <p id=”ex”></p> <script> var day; switch (new Date().getDay()) { case

Continue reading Switch Statement – JavaScript Basics

Statements – JavaScript Basics

Statements are “instructions” to be “executed” by Web Browser. JS Statement This is a simple statement to write “Code Projects” inside Html element. <!DOCTYPE html> <html> <body> <h1>JS Statements</h1> <p>JS statements are executed by browser.</p> <p id=”ex”></p> <script> document.getElementById(“ex”).innerHTML = “Code Projects”; </script> </body> </html> Output :         JS Programs JS programs

Continue reading Statements – JavaScript Basics

Syntax – JavaScript Basics

It is the set of the rules how programs are constructed. JS Programs : A computer program is list of “instructions” to be “executed” by computer. These program instructions are called statements in programming language. JS Statements are separated by semicolons; <!DOCTYPE html> <html> <body> <h1>JS Statements</h1> <p id=”ex”></p> <script> var x, y, z; x = 2; y =

Continue reading Syntax – JavaScript Basics

Output – JavaScript Basics

Output can be displayed in different ways using JS. Using window.alert( ) This function is used to display a message alert. <!DOCTYPE html> <html> <body> <h1>Code Projects</h1> <p>Projects, Tutorials and More </p> <script> window.alert(“ALERT”); </script> </body> </html> Output : Using innerHTML document.getElementById(id) method can be used in JS to access HTML element. Html element is defined

Continue reading Output – JavaScript Basics

Where To – JavaScript Basics

<script> Tag : JavaScript code must be located between opening and closing script tags ; <script> and </script> tags. <!DOCTYPE html> <html> <body> <h1>JavaScript Basics</h1> <p id=”ex”></p> <script> document.getElementById(“ex”).innerHTML = “Hello World! This Is My First JavaScript”; </script> </body> </html> Output :       Block of JavaScript code that can be executed when “called” is

Continue reading Where To – JavaScript Basics