JAVASCRIPT FOR BEGINNERS: A Complete Beginners Guide To Learn The Fundamentals Of JavaScript, Python, SQL & Java by Mark Whistler

JAVASCRIPT FOR BEGINNERS: A Complete Beginners Guide To Learn The Fundamentals Of JavaScript, Python, SQL & Java by Mark Whistler

Author:Mark Whistler [Whistler, Mark]
Language: eng
Format: azw3, epub
Published: 2020-10-13T16:00:00+00:00


3.11 Working with Arrays

JavaScript has the ability to work with elements as arrays. This helps programmers to work with a continuous set of elements as shown below.

Example 19: The following program is used to showcase a simple JavaScript program that uses arrays.

<!DOCTYPE html>

<html>

<body>

<h1>Javascript Example</h1>

<p1 id="demo"></p1>

<script>

var val = ["1", "2", "3"];

document.getElementById("demo").innerHTML = val[0];

</script>

</body>

</html>

3.12 Working with Errors

JavaScript also has the ability to work with errors generated in the program by using try, catch blocks. The below example shows a simple program working with try, catch blocks.

Example 20: The following program showcases a simple JavaScript program that uses error handling.

<!DOCTYPE html>

<html>

<body>

<p id="demo"></p>

<script>

try {

funcA("Hello World");

}

catch(err) {

document.getElementById("demo").innerHTML = err.message;

}

</script>

</body>

</html>



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.