+1 vote
156 views
by (98.9k points)
Compare ES 5 and ES 6. Write a code in JavaScript to validate the email address entered by the user (check the presence of “@” character. If this character is missing, the script should display an alert box reporting the error and ask the user to reenter it again).

1 Answer

0 votes
by (98.9k points)
edited by
 
Best answer
Based on ES5 ES6
Definition ES5 is the fifth edition of the ECMAScript (a trademarked scripting language specification defined by ECMA International) ES6 is the sixth edition of the ECMAScript (a trademarked scripting language specification defined by ECMA International).
Release It was introduced in 2009. It was introduced in 2015.
Data-types ES5 supports primitive data types that are string, number, boolean, null, and undefined. In ES6, there are some additions to JavaScript data types. It introduced a new primitive data type 'symbol' for supporting unique values.
Defining Variables In ES5, we could only define the variables by using the var keyword. In ES6, there are two new ways to define variables that are let and const.
Performance As ES5 is prior to ES6, there is a non-presence of some features, so it has a lower performance than ES6. Because of new features and the shorthand storage implementation ES6 has a higher performance than ES5.
Support A wide range of communities supports it. It also has a lot of community support, but it is lesser than ES5.
Object Manipulation ES5 is time-consuming than ES6. Due to destructuring and speed operators, object manipulation can be processed more smoothly in ES6.
Arrow Functions In ES5, both function and return keywords are used to define a function. An arrow function is a new feature introduced in ES6 by which we don't require the function keyword to define the function.
Loops In ES5, there is a use of for loop to iterate over elements.

ES6 introduced the concept of for...of loop to perform an iteration over the values of the iterable objects

 

 

 

 

Code : 

 

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Email Validation</title>
</head>
<body>

<div>
  <label for="emailInput">Enter your email address:</label>
  <input type="text" id="emailInput" />
  <button onclick="validateEmail()">Validate Email</button>
</div>

<script>
  function validateEmail() {
    // Get user input from the input box
    const userEmail = document.getElementById('emailInput').value;

    // Check if "@" is present in the email
    if (userEmail && userEmail.includes('@')) {
      alert('Email address is valid: ' + userEmail);
    } else {
      alert('Invalid email address. Please re-enter.');
      // Clear the input box
      document.getElementById('emailInput').value = '';
    }
  }
</script>

</body>
</html>

Related questions

+1 vote
1 answer 309 views
+1 vote
1 answer 117 views

Doubtly is an online community for engineering students, offering:

  • Free viva questions PDFs
  • Previous year question papers (PYQs)
  • Academic doubt solutions
  • Expert-guided solutions

Get the pro version for free by logging in!

5.7k questions

5.1k answers

108 comments

557 users

...