Skip to main content

Posts

Showing posts from August, 2022

Javascript Constructor function and the new Operator with examples

In this tutorial, you will learn about the JavaScript constructor function and and the new Operator .how to use the new operator keyword objects. In  OOPs programming , before objects are created a very limited way and we did was to use some simple object literal, and now that all changes with constructor functions. A difference between a regular function and a constructor function is that we call a constructor function with the new operator. OK, Let's go into details. In JavaScript, A constructor is a special function used to create an object instance of a class. 'use strict'; // constructor function const User = function (firstName, lastName) { this.firstName = firstName; this.lastName = lastName; } //create an object const User = new User ('chandra' ,'kumar'); console.log(User); Output: chandra kumar In the above, the constructor is used to create a new object and set values of an existing object and the JavaScript calls the constructor ...

Html forms with examples

  What are HTML forms? An HTML form is the most important thing for all websites because the section of a document that contains it controls the input data such as input text, numbers, values, passwords, checkboxes, radio, buttons, submit, button, etc.   Html forms are generally used to collect the data from the user or customer and that is sent to the serves for processing validation and saving in the database. Html forms how to works? For examples: A customer wants to buy electronic items online, and the customer wants to add the details for the shipping address and then this payment to placed.  This process will be done by the HTML forms. Another example is all the applying government job websites you will need to enter your personal details like studying certificates, Day of birth, address for getting hall tickets..etc., so, Now you understand that the Html form is important for websites. Here, below form elements are used to send the data to the servers, and wi...

How to create a dynamically populate year in dropdownlist using javascript

In this tutorial, you will learn how to create a dynamically populate year in javascript with an example. In the HTML forms are need a dropdown with the select year for the date of birth, finance date between the date to pay the amount, etc..., Lots of the websites have hardcoded the date and year values. Here is the solution instead of hardcoding quick and super easy to dynamically populate year with the range using javascript. Read also: Difference between double equals and triple equals in javascript 8 Best Free keyword Research Tools Here, we are creating some basic HTML select tag <select> for id and the options get by the javascript using of javascript document.getElementById.    Html <select id="dateoption"></select> Javascript Code const dateoption = document.getElementById('dateoption'); let year =new Date().getFullYear(); let startyear = 2015; while(year >= startyear){ let options = document.createElement('option'); o...

Javascript ternary operator

In this tutorial, you will be going learn the javascript ternary operator and Examples There are two ways to write conditional operators the regular one is the if/else statement and another switch statement But there is another conditional operator it is a very nice and easy single-line conditional operator. There is javascript ternary operator is the only javascript operator takes the three operands : and followed by a Question mark. It works like an if/else statement and the ternary operator evaluates a condition and executes a block of code. syntax: condition? expression1: expression 2; How does the javascript ternary operator work? The ternary operator are want to execute the block of code. If the expression is executed the condition is true followed by the question mark and followed by a colon: expression executed the condition is false. condition? True: False; This example shows a message that a person can vote for the election if the age is greater than or equal ...

Difference between double equals == and triple equals === operator in javascript

In this tutorial, you will learn the difference between double equals == and triple equals === operator in javascript. In the comparison operators used to take decisions with if-else statements. But let's suppose we want to check two values are actually equal, instead of one being greater or less than the other. And for that, we have both double equals == and triple equals === this different equality operator is used on. $ads={1}   So let's start with a simple variable  const appleprice = 100; use = javascript operator assigns a value for the left operand and depends on the value that should be analyzed overall the program. if(appleprice == 100) console.log('1kg apple price rs.100); To make simple calculations with it. So let's now create an if statement, which will log to the console, If the person asks the apple price on the fruit stall and the stall person replies the price of the apple is rs 100, only if the person asking is the stall person. So we ...