0% found this document useful (0 votes)
3 views

exp-3 wt

The document illustrates features of ES5 and ES6 in JavaScript, highlighting methods like charAt(), trim(), and forEach() from ES5, and innovations such as arrow functions and template literals from ES6. It includes code examples demonstrating these features and emphasizes the transition from ES5 to ES6 as a significant evolution in JavaScript development. The conclusion notes that ES6 enhances productivity and code readability, empowering developers to create more robust applications.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

exp-3 wt

The document illustrates features of ES5 and ES6 in JavaScript, highlighting methods like charAt(), trim(), and forEach() from ES5, and innovations such as arrow functions and template literals from ES6. It includes code examples demonstrating these features and emphasizes the transition from ES5 to ES6 as a significant evolution in JavaScript development. The conclusion notes that ES6 enhances productivity and code readability, empowering developers to create more robust applications.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Roll No:..160122733163….. Exp. No:…………..… Date:…………………..

AIM: To illustrate few es5 features and few es6 features.


DESCRIPTION:

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>

Page No. …………………….. Signature of the Faculty………………………...


Roll No:..160122733163….. Exp. No:…………..… Date:…………………..

<script> var str = "es5 features"; var a = str.charAt(0);


document.write("charAt(0) for the string 'es5 features' is " + a);
</script>
<br><br>
<hr>
<h2>Trim Method</h2>
<script> var str = " es5
features "; var l1 = str.length;
var a = str.trim(); var l2 = a.length;
document.write("Trim function for the string 'es5 features' is done and the length of
original string is " + l1 + " and the length of trimmed string is " + l2);
</script>
<br><br>
<hr>

<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 = [];

Page No. …………………….. Signature of the Faculty………………………...


Roll No:..160122733163….. Exp. No:…………..… Date:…………………..

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>

Page No. …………………….. Signature of the Faculty………………………...


Roll No:..160122733163….. Exp. No:…………..… Date:…………………..

<script> var a = [1, 2, 3, 4, 5]; var


squared = a.map(function (element) { return
element * element;
});
document.write("Squared elements of the array [" + a + "] are: " + squared);
</script>
<br><br>
<hr>
<h2>Array.filter() Method</h2>
<script> var a = [10, 15, 20, 25, 30]; var
divisibleByFive = a.filter(function (element) { return
element % 5 === 0;
});
document.write("Elements divisible by 5 in the array [" + a + "] are: " +
divisibleByFive);
</script>
<br><br>
<hr>
<h2>Array.reduce() Method</h2>
<script> var a = [1, 2, 3, 4, 5]; var sum = a.reduce(function
(accumulator, currentValue) { return accumulator + currentValue;
}, 0);
document.write("Sum of elements in the array [" + a + "] is: " + sum); </script>
<br><br>
<hr>
<h2>Date.now() Method</h2>
<script>

Page No. …………………….. Signature of the Faculty………………………...


Roll No:..160122733163….. Exp. No:…………..… Date:…………………..

document.write("Current timestamp using Date.now() is: " + Date.now());


</script>
<br><br>
<hr>
<h2>Date.toISOString() Method</h2>
<script> var currentDate = new
Date();
document.write("Current date and time in ISO 8601 format using
Date.toISOString() is: " + currentDate.toISOString());
</script>
<br><br>
<hr>
<h2>ES6 Features</h2>
<h3>Arrow Functions</h3>
<script> var multiplyByTwo = x
=> x * 2;
document.write("Result of arrow function multiplyByTwo(5): " + multiplyByTwo(5));
</script>
<br><br>
<hr>
z <h3>Template Literals</h3>
<script> var name = "John";
var greeting = Hello, ${name}!;
document.write(greeting);
</script>
<br><br>
<hr>

Page No. …………………….. Signature of the Faculty………………………...


Roll No:..160122733163….. Exp. No:…………..… Date:…………………..

<h3>Let and Const Declarations</h3>


<script> let x = 10; const y = 20;
document.write("Value of x: " + x + ", Value of y: " + y);
</script>
<br><br>
<hr>
<h3>Destructuring Assignment</h3>
<script> var [a, b] = [10, 20]; document.write("Value of
a: " + a + ", Value of b: " + b);
</script>
<br><br>
<hr>
<h3>Spread Operator</h3>
<script> var arr1 = [1, 2, 3]; var arr2 = [...arr1, 4, 5];
document.write("Result of spread operator: " + arr2);
</script>
<br><br>
<hr>
</div>
</body>
</html>

Page No. …………………….. Signature of the Faculty………………………...


Roll No:..160122733163….. Exp. No:…………..… Date:…………………..

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.

Page No. …………………….. Signature of the Faculty………………………...

You might also like