Sign Up to our social questions and Answers to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers to ask questions, answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This category lists all questions and answers related to the Javascript programming language.
How to Print to Console in Javascript
There are various ways to to console info. Here are some important methods of console API console.log() console.log(123); //number console.log("Hello World!"); //string console.log(10 + 20); //expression console.log(new Date()); //object console.clear() console.log(10); console.log("Hello World!");Read more
There are various ways to to console info.
Here are some important methods of console API
console.log()
console.clear()
console.error()
console.assert()
console.table() :
console.time() and console.timeEnd()
What Does NaN Mean in Javascript
NaN is Not-A-Number. There are five different types of operations that return NaN:Number cannot be parsed (e.g. parseInt("blabla") or Number(undefined))Math operation where the result is not a real number (e.g. Math.sqrt(-1))Operand of an argument is NaN (e.g. 7 ** NaN)Indeterminate form (e.g. 0 * IRead more
NaN is Not-A-Number.
There are five different types of operations that return NaN:
Number cannot be parsed (e.g. parseInt(“blabla”) or Number(undefined))
Math operation where the result is not a real number (e.g. Math.sqrt(-1))
Operand of an argument is NaN (e.g. 7 ** NaN)
Indeterminate form (e.g. 0 * Infinity, or undefined + undefined)
Any operation that involves a string and is not an addition operation (e.g. “foo” / 3)
ex:
What is the type of NaN?
The type of NaN, which stands for Not a Number is, surprisingly, a number. The reason for this is, in computing, NaN is actually technically a numeric data type. However, it is a numeric data type whose value cannot be represented using actual numbers
See lessHow to Convert Set to Array in Javascript
I believe this is onne of the most vital info for me. Annd i'm glad studying your article. However wanna remark on some basic issues, The website taste is wonderful, the articles is truly excellent : D. Just rikght process, cheers
I believe this is onne of the most vital info for me.
See lessAnnd i’m glad studying your article. However wanna remark on some basic issues, The website taste is
wonderful, the articles is truly excellent : D. Just rikght process, cheers
What is innerhtml in javascript
InnerHTML is a property of every element. It tells you what is between the starting and ending tags of the element, and it also let you sets the content of the element. innerHTML will show the value and apply any HTML formatting. Ex: HTML: <div id='content'> Hi this is awesome </div> js:Read more
InnerHTML is a property of every element. It tells you what is between the starting and ending tags of the element, and it also let you sets the content of the element.
innerHTML will show the value and apply any HTML formatting.
Ex:
HTML:
js:
ouput:
(in h1 style) innerHTML apply any HTML formatting in string.
InnerText:
InnerText wont apply HTML formatting
ex:
See lessHow to empty an array in JavaScript
There are 4 ways to empty array: method 1 (set length of variable as 0) ex: let arr=[1,2,3,4,5,6] arr.length=0 console.log(arr) output: [] Method 2 (Assign empty array to variable) ex: let arr=[1,2,3,4,5,6] arr=[]; console.log(arr) output: [] Method 3 (Using splice) let arr=[1,2,3,4,5,6] arr.splicRead more
There are 4 ways to empty array:
method 1 (set length of variable as 0)
ex:
Method 2 (Assign empty array to variable)
ex:
Method 3 (Using splice)
Method 4 (by popping)
See lessHow do I convert Javascript object to json
short answer: use JSON.stringify() There are 3 ways to use this: JSON.stringify(value, replacer)JSON.stringify(value)JSON.stringify(value, replacer)JSON.stringify(value, replacer, space) Below is demonstration JSON.stringify(value)// convert obj to jsonex:let obj={"name": "srikanth", age:26, phoneNRead more
short answer:
use JSON.stringify()
There are 3 ways to use this:
Below is demonstration
output:
{“name”:”srikanth”,”age”:26,”phoneNo”:9321234576}
JSON.stringify(value, replacer)
( to select keys in object)
output:
{“name”:”srikanth”,”age”:26}
JSON.stringify(value, replacer, space)
(to format output of stringified json)
output:
See less{
“name”: “srikanth”,
“age”: 26,
“phoneNo”: 9321234576
}
How to Hide API key in Javascript
When you need to hide the API key in JS you have to define the key as "Password" and on the click event of a button if you need to show that password value set "Text" on button click event. Suppose you visit login page of gmail. When you type your password it shows like "*********" in this format bRead more
When you need to hide the API key in JS you have to define the key as “Password” and on the click event of a button if you need to show that password value set “Text” on button click event.
Suppose you visit login page of gmail.
When you type your password it shows like “*********” in this format but when you click on an eye button it shows your password.
So what you need to do in this case when you define such area or something please defined the type as Password and when you want to show that particular set the type as Text on a button click event.
See lessHow to Import or include a JavaScript file inside another JavaScript file?
Earlier javascript was not having any feature to import and export javascript but since the discovery of ECMAScript 6 (or ES6) you can use the export or import statement in a JavaScript file to export or import variables, functions, classes, or any other entity to/from other JS files. Suppose we havRead more
Earlier javascript was not having any feature to import and export javascript but since the discovery of ECMAScript 6 (or ES6) you can use the export or import statement in a JavaScript file to export or import variables, functions, classes, or any other entity to/from other JS files.
Suppose we have two files named script.js and app.js and you want to export variables and functions script.js to app.js Then in the “script.js” file you need to write the export statement as shown in the following example:
Example :
let message = “Hi How are you doing?”;
const PI = 3.14;
function addNumbers(a, b){
return a + b;
}
// Exporting variables and functions
export { message, PI, addNumbers };
And in the “app.js” file you need to write the import statement as shown below:
import { message, PI, addNumbers } from ‘./script.js’;
console.log(message); // Prints to the console : Hi How are you doing?
See lessconsole.log(PI); // Prints to the console : 3.14
console.log(addNumbers(10, 10)); // Prints to the console : 20
How do I append an object to an array in JavaScript?
Use the push() function to append to an array:[code]// initialize array var arr = [ "Adam", "panju", "keri" ];// append new value to the array arr.push("oraask");console.log(arr);[/code]Will print["Adam", "panju", "keri", "oraask"]
Use the push() function to append to an array:
[code]// initialize array
var arr = [
“Adam”,
“panju”,
“keri”
];
// append new value to the array
arr.push(“oraask”);
console.log(arr);[/code]
Will print
See lessHow to set a checkbox to be “checked” and “uncheck” with JQuery 1.5 & 1.6 ?
jQuery 1.6+ Use the new .prop() method: [code]$('.myCheckbox').prop('checked', true); $('.myCheckbox').prop('checked', false);[/code] jQuery 1.5.x and below The .prop() method is not available, so you need to use .attr(). [code]$('.myCheckbox').attr('checked', true); $('.myCheckbox').attr('checked',Read more
jQuery 1.6+
Use the new .prop() method:
[code]$(‘.myCheckbox’).prop(‘checked’, true);
$(‘.myCheckbox’).prop(‘checked’, false);[/code]
jQuery 1.5.x and below
The .prop() method is not available, so you need to use .attr().
[code]$(‘.myCheckbox’).attr(‘checked’, true);
$(‘.myCheckbox’).attr(‘checked’, false);[/code]
Note that this is the approach used by jQuery’s unit tests prior to version 1.6 and is preferable to using
[code]$(‘.myCheckbox’).removeAttr(‘checked’);[/code]
since the latter will, if the box was initially checked, change the behaviour of a call to .reset() on any form that contains it – a subtle but probably unwelcome behaviour change.
For more context, some incomplete discussion of the changes to the handling of the checked attribute/property in the transition from 1.5.x to 1.6 can be found in the version 1.6 release notes and the Attributes vs. Properties section of the .prop() documentation.
See less