exp-3 wt
exp-3 wt
ES5, with its charAt(), trim(), isArray(), and forEach() methods, revolutionized JavaScript by
offering simpler ways to manipulate strings and arrays, thereby facilitating common
operations. In contrast, ES6 introduced game-changing features like arrow functions,
template literals, let and const declarations, destructuring assignment, and the spread operator.
These advancements not only streamlined code syntax but also empowered developers to
write cleaner, more concise, and more maintainable code. ES6's innovations marked a
significant leap forward for JavaScript, enabling developers to build more efficient and
sophisticated web applications with ease.
CODE:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ES5 Features</title>
<style> body{
width: 50%; margin-left:
300px;
}
.features{ border: 2px
solid black;
}
</style>
</head>
<body>
<div class="features">
<h2>CharAt() Method</h2>
<h2>IsArray() Method</h2>
<script> var chocolates = ["Lindt", "Ferrero Rocher",
"Toblerone"];
document.write(chocolates + " is an array? " + Array.isArray(chocolates));
</script>
<br><br>
<hr>
<h2>Array.forEach() Method</h2>
<script> var a = [10, 20, 30,
40, 50]; var result = [];
a.forEach(element => {
var s = element * 2;
result.push(s);
});
document.write("Array used is " + a + ", upon performing *2 for each
element:<br>"); document.write(result.join(', '));
</script>
<br><br>
<hr>
<!-- Add more ES5 features below -->
<h2>Array.every() Method</h2>
<script> var a = [2, 4, 6, 8, 10]; var
isEven = a.every(function (element) { return
element % 2 === 0;
});
document.write("Are all elements of the array [" + a + "] even? " + isEven);
</script>
<br><br>
<hr>
<h2>Array.lastIndexOf() Method</h2>
<script> var a = [10, 20, 30, 40, 50,
20]; var lastIndex = a.lastIndexOf(20);
document.write("Last index of '20' in the array [" + a + "] is " + lastIndex);
</script>
<br><br>
<hr>
<h2>Array.map() Method</h2>
OUTPUT:
CONCLUSION:
In conclusion, while ES5 laid the groundwork for modern JavaScript development by
introducing essential methods for string and array manipulation, ES6 elevated the language to
new heights with its array of powerful features. The transition from ES5 to ES6 marked a
significant evolution in JavaScript, enabling developers to write cleaner, more expressive, and
more efficient code. By embracing ES6's innovations such as arrow functions, template
literals, and destructuring assignment, developers can enhance productivity, improve code
readability, and build more robust applications. Ultimately, the adoption of ES6 represents a
pivotal moment in the evolution of JavaScript, empowering developers to tackle complex
challenges with confidence and creativity.