Skip to main content

Posts

Showing posts with the label check null values in JavaScript

How To modify the URL of page without reloading the page?

To modify the URL of page without reloading the page - To modify the URL of page without reloading the page using the “push State” function. Example – window . history . pushState ( 'page1' , 'This is page1 Title' , '/index.htm' ); ü   Stayed Informed –   Object Oriented JavaScript Interview Questions I hope you are enjoying with this post! Please share with you friends!! Thank you!!!

How To convert JSON String to Object?

To convert JSON String to Object - To convert JSON String to Object in JavaScript using the “JSON.parse()”. Example - let jsonData = '{"name":"Anil Singh","Age":33, "URL" :"https://code-sample.com"}' ; let objectData = JSON . parse ( jsonData ); console . log ( objectData ); ü   Stayed Informed –   Object Oriented JavaScript Interview Questions I hope you are enjoying with this post! Please share with you friends!! Thank you!!!

“Happy New Year” Count Down [JavaScript Code]

In this post, I am going to share the “ JavaScript ” code sample download link to get “ Happy New Year! ” Count down watch. Actually, I am using a JavaScript functions to calculate and execute automatically your upcoming “ NEW YEAR ” Remaining times [ DAYS – HOURS – MINUTES - SECONDS ]. You can see the result after click in the below mention demo link. Stay Informed – Demo Link… Try the “ Live examples ” of the code shown in this page. Examples as, <script> $( function () { var initializeWatchClock = function (id, endtime) { var clock = document .getElementById(id); var daysSpan = clock.querySelector( '.days' ); var hoursSpan = clock.querySelector( '.hours' ); var minutesSpan = clock.querySelector( '.minutes' ); var secondsSpan = clock.querySelector( '.seconds' ); var updateWatchClock = function () { var t = getTimeRemaining(endtime); ...

What is DOJO toolkit?

DOJO is a rapid development toolkit for web oriented software on desktop and mobile and internet applications without using the browser’s inbuilt graphics technology.  DOJO is being used by all the popular internet browsers like Internet Explorer, Google Chrome, Safari, Firefox, and Opera and on smart phones and tablets by Apple (iPhone, iPod) Google (Android) and BlackBerry. DOJO provides us many widgets , utilities and AJAX libraries to develop our applications. DOJO provides the connection between DOM element and DOJO function and also contains many DOM elements looks like, 1.       HTML, 2.       SVG and 3.       Style packages. DOJO is helping us to create rich and interactive web applications and it is similar like Comet and Ajax . Dojo has great support for integrating with back end data store. It works seamlessly with REST services . We even extended Dojo's J...

JavaScript convert string to Boolean

//BELOW METHOD IS USED TO CONVERT STRING VALUE TO BOOL function getBoolean(val) {     return !! JSON.parse (String(val).toLowerCase()); }

JavaScript/jQuery Special Characters Validation example

Hello everyone, I am going to share the special characters validation using JavaScript/jQuery. The input special characters   !@#$%^&*()_+~{}[]';:"/.,< >? Example as given below $( function () {    $( "form :input[type='text']" ).on( "keyup" , function (e) {         var inputTextId = $( '#' + this .id);         var inputText = inputTextId.val();         var errorFor = this .id ;         if (!isValidChar(inputText)) {             $( '#' + this .id).val( '' ).valid();                     setTimeout( function () { replaceErrorMsg(errorFor); }, 100);         }      });   });   fu...

What is ‘this’ in JavaScript?

Hello everyone, today's I am going to share a basic and very confusing concepts that is called 'this' keyword :) The  'this' keyword  behaves a little differently in  JavaScript  compared to other languages. In most of the other languages, ' this ' keyword is a reference to the current object instantiated by the classes  and methods.  In the JavaScript  languages , 'this' keyword refers to the object which 'owns' the method, but it depends on how a function is called. The examples in details as given below. //Global Scope in JavaScript //In the below example, ‘this’ keyword refers to the global object. window .sms = "Hi, I am window object" ; console .log ( window .sms); console .log (this.sms); // Hi, I am window object. console .log ( window === this); // Its return true. //Calling a Function in JavaScript //In the below example, ‘this’ keyword remains the global object if we are calling a function. wi...

How do I check for null values in JavaScript?

JavaScript is very flexible languages. When you checking to null  values for JavaScript variable like below email, password and mobile. I'm guessing you are actually looking for null password  == null , email == null and mobile == null but this code are not working. i.e. if (password == null && email == null && mobile == null ) {     //This code is not working. } In this scenario, you need to write this simpler code will work fine as give below. You simply need to check  null   value using the (!) operator and achieve it :) if (!password && !email && !mobile) {     //This code is working. } // !password, !email and !mobile will check for empty string, null, undefined, false and 0 and NaN etc. Thank you!

Object in JavaScript - Object Creation by Constructor, Function and Prototype

How to create a JavaScript object? The JavaScript object  is a collection of properties and the each property associated with the name-value pairs . The object can contain any data types (numbers, arrays, object etc.) The example looks like, Var myObject= {empId : “001”, empCode :”X0091”}; In the above example, here are two properties one is empId and other is empCode and its values are “001” and “X0091”. The properties name can be string or number. If a property name is number i.e. Var numObject= {1 : “001”, 2 :”X0091”}; Console.log(numObject.1);   //This line throw an error! Console.log(numObject[“1”]);   // will access to this line not get any error! As per my thought, the number property name should be avoided. Types of creating an object ( There are two types ) 1.       Object literals 2.       Object constructor Object Literals : This is the most common way to ...