How to get a timestamp in JavaScript

Below are the ways to get a timestamp in Javascript.

Date.now returns the UTC timestamp in milliseconds.

If you are using IE you can use the below code.

if (!Date.now) {
    Date.now = function now() {
        return new Date().getTime();
    };
}
To convert the timestamp in seconds use below code

Math.floor(Date.now() / 1000)

jQuery Tutorial for Beginners - Hello World Example

Below is a Jquery example of how to print "Hello World" to the Console.

<html>
<head>
<title>jQuery Example in Developersarena</title>
<script type="text/javascript" 
   src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
</script>
<script type="text/javascript">
   $(document).ready(function(){
      document.write("Hello, World!");
   });
</script>   
</head>
<body>
<h1>Hello</h1>
</body>
</html>

Top 10 frequently asked JQUERY interview questions

Below are the top 10 Jquery questions that are frequently asked in Interviews

1.  What is JQUERY ?

jQuery is a fast, small, and feature-rich JavaScript library. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers.

2 . What is difference between jQuery's ready and holdReady ?
jQuery's ready is an event which gets triggered automatically when DOM is ready while holdReady is a signal/flag to hold this triggering. holdReady was included in 1.6 version and it works only if used before the execution/triggering of ready event. Once ready event is fired, it has nothing to do. It is useful in dynamically loading scripts before the ready starts. It release ready event execution when used with a true parameter

3. How do you update ajax response with id " username"

function updateStatus() {
     $.ajax({
            url: 'updateUsrName.htm',
            success: function(response) {
             // update username
             $('#username').html(response);
         }
     });
}


4. How do you get the text value of a selected option in JQUERY ?

$("#proglang").val();
<select id="proglang">
   <option value="1">Java</option>
   <option value="2">Javascript</option>
   <option value="3">Jquery</option>
   <option value="4">Visual Basic</option>
   <option value="5">Unix</option>
</select>

$("#proglang option:selected").text();

5.Name any four paremeter of Jquery ajax method

data : Specifies data to be sent to the server
url : Specifies the URL to send the request to. Default is the current page
type : Specifies the type of request. (GET or POST)
cache: A Boolean value indicating whether the browser should cache the requested pages. Default is true beforeSend(xhr): A function to run before the request is sent

5.What is $() in jQuery library?

 $() function is used to wrap any object into jQuery object, which then allows you to call various method defined jQuery object. You can even pass a selector string to $() function, and it will return jQuery object containing an array of all matched DOM elements.

6 . Difference between JavaScript window.onload event and jQuery ready function?

Main difference between JavaScript onload event and jQuery ready function is that former not only waits for DOM to be created but also waits until all external resources are fully loaded including heavy images, audios and videos.  If loading images and media content takes lot of time that user can experience significant delay on execution of code defined in window.onload event. On the other hand jQuery ready() function only wait for DOM tree, and does not wait for images or external resource loading, means faster execution. Another advantage of using jQuery $(document).ready() is that you can use it multiple times in your page, and browser will execute them in the order they appear in HTML page, as opposed to onload technique, which can only be used for a single function. Given this benefits, it's always better to use jQuery ready() function than JavaScript window.onload event.

7. How can you call a method inside code-behind using jQuery ?
We can call a method inside code-behind By $.ajax and by declaring method a WebMethod

8.What are the advantages of JQUERY ?

The main advantages to adding jQuery are :
  • browser compatibility - doing something like .attr() is much easier than the native alternatives, and won't break across browsers.
  • simplification of usually complicated operations - if you'd like to see a well written cross browser compatible version of an XHR method, take a look at the source for $.ajax - for this method alone it's almost worth the overhead of jQ.
  • DOM selection - simple things like binding events & selecting DOM elements can be complicated and differ per-browser. Without a lot of knowledge, they can also be easily written poorly and slow down your page.
  • Access to future features - things like .indexOf and .bind are native javascript, but not yet supported by many browsers. However, using the jQuery versions of these methods will allow you to support them cross browser.
9. What is the difference between onload() and document.ready() function used in jQuery

  • We can have more than one document.ready() function in a page where we can have only one body unload function.
  • document.ready() function is called as soon as DOM is loaded where body.onload() function is called when everything gets loaded on the page that includes DOM, images and all associated resources of the page.
  • Document.ready() function is called as soon as DOM is loaded.
  • onload() function is called when everything (DOM, images)gets loaded on the page.
10. What is difference between jQuery.get() and jQuery.ajax() method?

ajax() method is more powerful and configurable, allows you to specify how long to wait and how to handle error, get() is a specialization to over ajax just to retrieve some data.

Oracle PL/SQL - INSTRB function

In this tutorial we will explain how to use the Oracle PL/SQL INSTRB  function with syntax and examples

INSTRB Function : 

Syntax : INSTRB ('input_string',  'search_string',  start_position,  occurrence);

  • In Oracle PL/SQL INSTRB function returns the position of the "search_string" in the given input_string using bytes instead of characters.
  • input_string  and search string can be of data types CHAR, VARCHAR2, NCHAR, NVARCHAR2, CLOB, or NCLOB
  • return type is of data type NUMBER.
  • The first position in the input_string is treated as 1.
  • start_position is the position in the input_string from where the search will start.
  • If start_position is negative, then Oracle counts backward from the end of string and then searches backward from the resulting position.
  • occurrence must be a positive integer.
  • If search_string is not found in input_string, then the INSTRB function will return 0.
  • start_position and occurrence are optional and the default value is 1.
EXAMPLE 1 :

SELECT INSTRB('DEVELOPERS ARENA','E',3, 2)
  "INSTRING_POSITION" FROM DUAL;
 
  INSTRING_POSITION
-------------------
                  8
EXAMPLE 2 :

SELECT INSTRB('DEVELOPERS ARENA','E',-2, 3)
  "INSTRING_POSITION" FROM DUAL;
 
  INSTRING_POSITION
-------------------
                  4

Oracle PL/SQL - SIGN function

In this tutorial we will explain how to use the Oracle PL/SQL SIGN function with syntax and examples

SIGN Function : 

Syntax : SIGN(input_number) ;

  • In Oracle PL/SQL , SIGN is a inbuilt function which is used to determine the sign of a give number.
  • Returns -1 if input_number is < 0
  • Returns 1 if input_number is > 0
  • Returns 0 if input_number is = 0
  • Return type is number and is either -1 ,1 or 0.


EXAMPLE :1 (When Input number is < 0 )

SELECT SIGN(-100) FROM DUAL;

SIGN
--------------------
-1
EXAMPLE :2 ( When Input number is > 0)

SELECT SIGN(143.12) FROM DUAL;

SIGN
--------------------
1
EXAMPLE :3 (When Input number is = 0 )

SELECT SIGN(0) FROM DUAL;

SIGN
--------------------
0

Oracle PL/SQL - CURRENT_DATE function

In this tutorial we will explain how to use the Oracle PL/SQL CURRENT_DATE function with syntax and examples

CURRENT_DATE Function : 

Syntax : CURRENT_DATE ;

  • CURRENT_DATE returns the current date in the session time zone, in a value in the Gregorian calendar of datatype DATE.
  • Return type is of data type DATE.
  • There are no input parameters to this function.
  • The output date can be altered by changing the timezone.

In the below Example 1 the CURRENT_DATE returns the date as per the timezone of UTC-5 and in NLS_DATE_FORMAT of DD-MON-YYYY HH24:MI:SS

In Example 2 , the session is altered to a timezone of UTC-7.

EXAMPLE :1 

ALTER SESSION SET TIME_ZONE = '-5:0';

SELECT CURRENT_DATE FROM DUAL;

CURRENT_DATE
--------------------
31-MAR-2015 18:14:08
EXAMPLE :2

ALTER SESSION SET TIME_ZONE = '-7:0';

SELECT CURRENT_DATE FROM DUAL;

CURRENT_DATE
--------------------
31-MAR-2015 16:14:08