Found 6710 Articles for Javascript

How to execute a cube of numbers of a given array in JavaScript?

vineeth.mariserla
Updated on 30-Jul-2019 22:30:26

1K+ Views

To find the cubes of elements of given array we need to run a for loop to access each and every element and we need to use "=" operator to replace elements with their cubes.To get the desired values the below steps need to be followed.Steps1) Declared an array a = [1, 2, 3, 4, 5]2) For loop was introduced to access each and every element in the array(a[i]).3) Inside for loop "=" operator is used to replace the element with their cubic values(a[i]*a[i]*a[i]).so, from the above steps the output obtained will be 1, 8, 27, 64, 125.By following the ... Read More

Explain JavaScript Bitwise NOT, Left shift and Right shift?

vineeth.mariserla
Updated on 30-Jul-2019 22:30:26

208 Views

JavaScript Bitwise NOT Live DemoExample document.getElementById("not").innerHTML = ~ 13; Output-14Explanation: It gives 0 for 1 and 1 for 0.The above result is 14.JavaScript Bitwise leftshift operator Live DemoExample document.getElementById("left").innerHTML = 5

What are the types of tags involved in javascript?

vineeth.mariserla
Updated on 30-Jul-2019 22:30:26

1K+ Views

Html taga) The tag is used to define a client-side script.b) The tag  contains scripting statements or an external script file.JavaScript code must be keep in script tag.Let's see the use of the tag. For suppose declare the variable outside the script tag. Live DemoExample var a = 1;    var b = 2;    var c = a + b; document.getElementById("tag").innerHTML = c; Outputvar a = 1For suppose, let the variable be declared inside the script tag. Live DemoExample    var a = 1;    var b = 2;    var c = a + b; document.getElementById("tag").innerHTML = c; Output3

Write the syntax of javascript with a code to demonstrate it?

vineeth.mariserla
Updated on 30-Jul-2019 22:30:26

215 Views

JavaScript TagsThe html script tag wants the browser to get a script between them. We can expect the scripts to be in the following places. 1.The script can be placed in html's head tag 2.Within Html's body tag. 3.As an external file. Most importantly client side scripts such as JavaScript are placed in script tags.demonstration code  Live Demo This example writes "JavaScript is not java" into an HTML element with id="script"    document.getElementById("imp").innerHTML = "JavaScript is not java"; OutputThis example writes "JavaScript is not java" into an HTML element with id="script" JavaScript is not javaExplanationEvery JavaScript code should be in ... Read More

How to display output in javascript?

vineeth.mariserla
Updated on 30-Jul-2019 22:30:26

2K+ Views

There are 4 ways to display the output in JavaScript. a) Displaying the output in HTML elements, using innerHTML attribute.  Live DemoExample document.getElementById("display").innerHTML = 10 + 10; Output20.b) Displaying the output using document.write(). Live DemoExample document.write(2 + 3); Output5c) Displaying the output through console.log().  Live DemoExample console.log(2 + 3); In debugger console, the output5.d) Displaying the output through alert box. Live DemoExample alert(2 + 3); In alert window box, the output5In case of handling json strings, or some other big data console.log is the best choice.

How to add an element to a JavaScript object?

Vivek Verma
Updated on 02-Sep-2023 11:27:38

74K+ Views

In JavaScript, the object is a real-time entity that contains properties and methods. In simple words, we can say that object is an instance of a class. It stores the data in the form of key and value pairs. The keys are usually referred to as properties and the values are referred to as property values. There are two ways to define an object in JavaScript. Syntax var obj = new Object(); (or) var obj = {property1: value, property2 : value2 …….} Using dot (.) operator In JavaScript, using the dot (.) operator we can access a variable ... Read More

Write a number array and add only odd numbers?

vineeth.mariserla
Updated on 30-Jul-2019 22:30:26

1K+ Views

Odd number summation using JavaScript. Live DemoExample var tot = 0; var a = [1,45,78,9,78,40,67,76]; for(var i = 0; i

Write a number array and using for loop add only even numbers in javascript?

Vivek Verma
Updated on 29-Aug-2022 10:01:31

2K+ Views

An array in JavaScript is an datatype which contains similar types of data. A number array is defined as the array object with numbers as its content. These numbers are divided into even and odd types on a basic level of mathematics. In this article, we will look into outputting the even number of any number array. Syntax let arr = [val1, val2, val3, …]; Now, let us consider an array arr with numbered elements and print the content in the 0th index − Example let ... Read More

Explain about add and assignment(+=) operator in detail in javascript?

vineeth.mariserla
Updated on 30-Jul-2019 22:30:26

201 Views

add and assignment(+=) operatorThe add and assignment(+=) operator reduces the code little bit.It may not much influential  in small codes whereas coming to long codes it's use can't be ignored. Live DemoExample    var tot = 0;    var a = [1,45,78,9,78,40];    for(var i = 0; i

Explain about logical not(!) operator in detail with example in javascript?

vineeth.mariserla
Updated on 30-Jul-2019 22:30:26

162 Views

NOT operatorThe logical NOT operator gives true for false values and false for true values. Live DemoExample var x = 200; var y = 300; document.getElementById("logical").innerHTML = !(x < y) + "" + !(x > y); Outputfalse true

Advertisements