You are here: Home / Topics / Search / JavaScript
Showing 46 Search Results for : JavaScript

Arrow Function in JavaScript

Filed under: JavaScript on 2023-08-07 19:00:15
In this post, we are going to show you arrow function. Watch the below example carefully.<!DOCTYPE html><html><body><h1>JavaScript Functions</h1><h2>The Arrow Function</h2><p>This example shows the syntax of an Arrow Function, and how to use it.&l

How to Iterate an array elements using For Loop in JavaScript

Filed under: JavaScript on 2023-08-06 23:04:29
In this post, you will see how you can iterate elements of an array in javascript.Note: here we have an array of numbers.We can find the number of elements in this array by using array.length i.e 6. Now we will run for loop six times to print all the elements.All of you know that array starts w

For Loop Iteration In JavaScript

Filed under: JavaScript on 2023-08-06 22:39:18
In this example, we will see for loop iteration. We have taken one blank array. We will push the values in this array using for loop. Below is the complete example of this action.<!DOCTYPE html><html lang="en"><head>   <meta charset="UTF-8">   <meta nam

While Loop example in JavaScript

Filed under: JavaScript on 2023-08-06 22:03:24
In this post we will see while loop in JavaScript. While loop keep working until the condition is true. As soon as the condition is false it stops.For example we have taken one array here and we will push the values in this array with the help of while loop.<!DOCTYPE html><html lang="en">

Return the Remainder from Two Numbers in JavaScript

Filed under: JavaScript on 2023-08-06 21:08:07
There is a single operator in JavaScript, capable of providing the remainder of a division operation. Two numbers are passed as parameters. The first parameter divided by the second parameter will have a remainder, possibly zero. Return that value. Examplesremainder(1, 3) ➞ 1remainder(3, 4) β

Write a code to find Maximum Edge of a Triangle in JavaScript

Filed under: JavaScript on 2023-08-06 21:00:59
Create a function that finds the maximum range of a triangle's third edge, where the side lengths are all integers. Examples:nextEdge(8, 10) ➞ 17nextEdge(5, 7) ➞ 11nextEdge(9, 2) ➞ 10 Notes:We will use this algorithm to find the maximum range of a triangle's third edge(side1 + side2)

Convert Hours into Seconds in JavaScript

Filed under: JavaScript on 2023-08-06 20:57:35
Write a function that converts hours into seconds. Examples:howManySeconds(2) ➞ 7200howManySeconds(10) ➞ 36000howManySeconds(24) ➞ 86400Notes:   60 seconds in a minute, 60 minutes in an hour <script>function howManySeconds(hour){var seconds = hour * 60 * 60 *;} v

Power Calculator in JavaScript

Filed under: JavaScript on 2023-08-06 20:54:31
Create a function that takes voltage and current and returns the calculated power.Examples:circuitPower(230, 10) ➞ 2300circuitPower(110, 3) ➞ 330circuitPower(480, 20) ➞ 9600Notes:Requires basic calculation of electrical circuits. Power = voltage * current; We will use this calculation in 

Return the First Element in an Array in JavaScript

Filed under: JavaScript on 2023-08-06 20:50:56
Create a function that takes an array containing only numbers and return the first element.Examples:getFirstValue([1, 2, 3]) ➞ 1

getFirstValue([80, 5, 100]) ➞ 80getFirstValue([-500, 0, 50]) ➞ -500Notes:The first element in an array always has an index of 0.Code: <script>function 

Write a code to print Cubes of any number in JavaScript

Filed under: JavaScript on 2023-08-06 20:48:07
In this program, we will make a function cubes(number) which will take number as parameter and will return cube of that number.cubes(3) ➞ 27
cubes(5) ➞ 125
cubes(10) ➞ 1000<script>function cubes(number){return number ** 3; //** means power }</script>

Convert Age to Days in JavaScript

Filed under: JavaScript on 2023-08-06 20:43:43
Create a function that takes the age in years and returns the age in days.Examples:calcAge(65) ➞ 23725

calcAge(0) ➞ 0

calcAge(20) ➞ 7300 Notes:Use 365 days as the length of a year for this challenge.Ignore leap years and days between last birthday and now.Expect only positive intege

Write a program in JavaScript to find the Area of Triangle

Filed under: JavaScript on 2023-08-06 20:41:33
Write a function that takes the base and height of a triangle and return its area.Examples:triArea(3, 2) ➞ 3

triArea(7, 4) ➞ 14

triArea(10, 10) ➞ 50 We will make a function triArea(base, height) which will take two values as parametersNotes:The area of a triangle is: (base * height)

Return the Next Number from the Integer Passed in JavaScript

Filed under: JavaScript on 2023-08-06 20:37:49
Create a function that takes a number as an argument, increments the number by +1 and returns the result.Examples:addition(0) ➞ 1

addition(9) ➞ 10

addition(-3) ➞ -2 code: <script>function addition(num){return num+1;} addition(0) // output 1addition(9) // output 10add

Convert Minutes into Seconds in JavaScript

Filed under: JavaScript on 2023-08-06 20:35:41
Write a function that takes an integer minutes and converts it to seconds.Examples:convert(5) ➞ 300

convert(3) ➞ 180

convert(2) ➞ 120 Code<script>function convert(minutes){return minutes * 60;  //1 minutes equals to 60 seconds.}convert(5) // output 300convert(3) // output

Return the Sum of Two Numbers in JavaScript

Filed under: JavaScript on 2023-08-06 20:33:00
Create a function that takes two numbers as arguments and returns their sum.Examplesaddition(3, 2) ➞ 5

addition(-3, -6) ➞ -9

addition(7, 3) ➞ 10 Code: <script>function addition(a, b){return a+b;} addition(3, 2); //output 5addition(-3, -6); //output -9addition(7, 3); 

What are the types of errors in javascript?

Filed under: JavaScript Interview Questions on 2022-08-06 09:35:56
There are two types of errors in javascript.Syntax error: Syntax errors are mistakes or spelling problems in the code that cause the program to not execute at all or to stop running halfway through. Error messages are usually supplied as well.Logical error: Reasoning mistakes occur when the syntax i

What is DOM?

Filed under: JavaScript Interview Questions on 2022-08-06 09:35:08
DOM stands for Document Object Model.  DOM is a programming interface for HTML and XML documents.When the browser tries to render an HTML document, it creates an object based on the HTML document called DOM. Using this DOM, we can manipulate or change various elements inside the HTML document.

What do you mean by BOM in Javascript?

Filed under: JavaScript Interview Questions on 2022-08-06 09:33:31
Browser Object Model is known as BOM. It allows users to interact with the browser. A browser's initial object is a window. As a result, you may call all of the window's functions directly or by referencing the window. The document, history, screen, navigator, location, and other attributes are avai

What do mean by prototype design pattern?

Filed under: JavaScript Interview Questions on 2022-08-05 07:33:58
The Prototype Pattern produces different objects, but instead of returning uninitialized objects, it produces objects that have values replicated from a template – or sample – object. Also known as the Properties pattern, the Prototype pattern is used to create prototypes.The introduction of bus

Explain WeakSet in javascript

Filed under: JavaScript Interview Questions on 2022-08-02 06:13:53
In javascript, a Set is a collection of unique and ordered elements. Just like Set, WeakSet is also a collection of unique and ordered elements with some key differences:Weakset contains only objects and no other type.An object inside the weakset is referenced weakly. This means, that if the object 

Why do we use callbacks in Javascript?

Filed under: JavaScript Interview Questions on 2022-08-02 06:12:44
A callback function is a method that is sent as an input to another function (now let us name this other function "thisFunction"), and it is performed inside the thisFunction after the function has completed execution.JavaScript is a scripting language that is based on events. Instead of waiting for

Methods to include JavaScript in HTML Code?

Filed under: JavaScript on 2022-07-16 17:12:56
Javascript can be added to our HTML code in mostly 2 ways:Internal Javascript: Javascript in this case is directly added to the HTML code by adding the JS code inside the <script> tag, which can be placed either inside the <head> or the <body> tags based on the requirement of the u

What are the features of JavaScript?

Filed under: JavaScript on 2022-07-16 17:11:22
Following are the features of javascript:It was developed with the main intention of DOM manipulation, bringing forth the era of dynamic websites.Javascript functions are objects and can be passed in other functions as parameters.Can handle date and time manipulation.Can perform Form Validation.A co

What is NaN property in JavaScript?

Filed under: JavaScript Interview Questions on 2022-07-04 19:30:33
NaN property represents the β€œNot-a-Number” value. It indicates a value that is not a legal number.typeof of NaN will return a Number.To check if a value is NaN, we use the isNaN() function,Note- isNaN() function converts the given value to a Number type, and then equates to NaN.isNaN("Hello") &n

Explain Hoisting in javascript

Filed under: JavaScript Interview Questions on 2022-07-03 07:56:47
Hoisting is the default behaviour of javascript where all the variable and function declarations are moved on top.This means that irrespective of where the variables and functions are declared, they are moved on top of the scope. The scope can be both local and global.Example 1:hoistedVariable = 3;

What are the different data types present in javascript?

Filed under: Javascript on 2022-07-02 07:56:54
To know the type of a JavaScript variable, we can use the typeof operator.Primitive types String - It represents a series of characters and is written with quotes. A string can be represented using a single or a double quote.Example :var str = "Vivek Singh Bisht"; //using double quotes
var str

What are disadvantage of JavaScript?

Filed under: JavaScript on 2022-06-29 18:09:25
Some of the disadvantages of JavaScript are:

a)    No support for multithreading
b)    No support for multiprocessing
c)    Reading and writing of files is not allowed
d)    No support for networking applications.

List some features of JavaScript

Filed under: JavaScript on 2022-06-29 18:07:32
Some of the features of JavaScript are:
1.    Lightweight
2.    Interpreted programming language
3.    Good for the applications which are network-centric
4.    Complementary to Java
5.    Complementary to HTML
6.    Open source
7.    Cross-platform 

What is JavaScript?

Filed under: JavaScript on 2022-06-29 18:06:48
JavaScript is a scripting language. It is different from Java language. It is object-based, lightweight, cross-platform translated language. It is widely used for client-side validation. The JavaScript Translator (embedded in the browser) is responsible for translating the JavaScript code for the we