Javascript Articles

Page 272 of 534

How to convert a Unix timestamp to time in JavaScript?

Smita Kapse
Smita Kapse
Updated on 15-Mar-2026 297 Views

To convert a Unix timestamp to time in JavaScript, you need to multiply the timestamp by 1000 (since Unix timestamps are in seconds, but JavaScript Date expects milliseconds) and then use Date methods to extract time components. What is a Unix Timestamp? A Unix timestamp represents the number of seconds that have elapsed since January 1, 1970, 00:00:00 UTC. JavaScript's Date constructor expects milliseconds, so we multiply by 1000. Example JavaScript Dates ...

Read More

What is the best way to initialize a JavaScript Date to midnight?

V Jyothi
V Jyothi
Updated on 15-Mar-2026 581 Views

To initialize a JavaScript Date to midnight, you need to set the time components (hours, minutes, seconds, and milliseconds) to zero using the setHours() method. Syntax date.setHours(hours, minutes, seconds, milliseconds) For midnight, use: date.setHours(0, 0, 0, 0) Example: Setting Current Date to Midnight var dt = new Date(); console.log("Original date:", dt.toString()); dt.setHours(0, 0, 0, 0); ...

Read More

How to convert PHP array to JavaScript array?

Jennifer Nicholas
Jennifer Nicholas
Updated on 15-Mar-2026 3K+ Views

Converting PHP arrays to JavaScript arrays is essential when passing server-side data to client-side scripts. PHP's json_encode() function provides a reliable way to achieve this conversion for both single and multidimensional arrays. Syntax // PHP side $phpArray = array('value1', 'value2'); // JavaScript side var jsArray = ; Example: Converting Simple PHP Array Let's start with a simple PHP array containing user information: var arr = ; console.log(arr); // Output: ["Amit", "amit@example.com"] console.log(arr[0]); // Output: "Amit" ...

Read More

How to get Euler's constant value in JavaScript?

Kumar Varma
Kumar Varma
Updated on 15-Mar-2026 914 Views

To get Euler's constant value in JavaScript, use the Math.E property. This represents Euler's constant and the base of natural logarithms, approximately 2.718281828459045. Syntax Math.E Example: Basic Usage You can access Euler's constant directly from the Math object: JavaScript Math E Property var property_value = Math.E; document.write("Euler's constant value is: " + property_value); ...

Read More

How to get Natural logarithm of 2 in JavaScript?

Paul Richard
Paul Richard
Updated on 15-Mar-2026 573 Views

To get the natural logarithm of 2 in JavaScript, use the Math.LN2 property. This built-in constant returns the natural logarithm of 2, which is approximately 0.693. Syntax Math.LN2 Return Value The Math.LN2 property returns a number representing the natural logarithm of 2, approximately 0.6931471805599453. Example Here's how to access the natural logarithm of 2: JavaScript Math LN2 Property ...

Read More

How to get Natural logarithm of 10 in JavaScript?

V Jyothi
V Jyothi
Updated on 15-Mar-2026 720 Views

To get the natural logarithm of 10 in JavaScript, use the Math.LN10 property. This built-in constant returns the natural logarithm of 10, which is approximately 2.302585092994046. Syntax Math.LN10 Return Value Returns a number representing the natural logarithm of 10 (ln(10) ≈ 2.302585092994046). Example JavaScript Math LN10 Property ...

Read More

What are runtime errors in JavaScript?

Rishi Rathor
Rishi Rathor
Updated on 15-Mar-2026 341 Views

There are three types of errors in programming: (a) Syntax Errors, (b) Runtime Errors, and (c) Logical Errors. Runtime errors, also called exceptions, occur during execution (after compilation/interpretation). For example, the following line causes a runtime error because here the syntax is correct, but at runtime, it is trying to call a method that does not exist. window.printme(); // printme() method doesn't exist Uncaught TypeError: window.printme is not a function Common Types of Runtime Errors JavaScript throws different types of runtime errors depending on the issue: ...

Read More

What is onmouseenter event in JavaScript?

Nishtha Thakur
Nishtha Thakur
Updated on 15-Mar-2026 375 Views

The onmouseenter event triggers when the mouse pointer enters an HTML element. Unlike onmouseover, it doesn't bubble and only fires when entering the target element itself, not its child elements. Syntax element.onmouseenter = function() { // Code to execute }; // Or in HTML Example: Basic Mouse Enter Event Here's how to use the onmouseenter event to display an alert when hovering over text: function sayHello() { ...

Read More

What is onkeypress event in JavaScript?

radhakrishna
radhakrishna
Updated on 15-Mar-2026 447 Views

The onkeypress event in JavaScript triggers when a user presses and releases a key while an element has focus. This event is commonly used with input fields, text areas, and other interactive elements to respond to user keyboard input. Syntax element.onkeypress = function(event) { // Handle keypress }; // Or in HTML Basic Example Here's how to use the onkeypress event to detect when a key is pressed in an input field: ...

Read More

Why JavaScript Data Types are Dynamic?

Sravani S
Sravani S
Updated on 15-Mar-2026 275 Views

JavaScript is a dynamically typed language, which means variables can hold different data types during program execution. Unlike statically typed languages where you must declare a variable's type upfront, JavaScript determines the type at runtime based on the assigned value. What Does Dynamic Typing Mean? In JavaScript, you don't need to specify whether a variable will store a string, number, or boolean. The same variable can be reassigned to hold completely different data types throughout the program. Example var val; ...

Read More
Showing 2711–2720 of 5,340 articles
« Prev 1 270 271 272 273 274 534 Next »
Advertisements