data types in javascript
JavaScript
/*JavaScript data types*/
//string
var string = 'ASCII text';
//int
var integer = 123456789;
//float
var float = 123.456;
//boolean, can be true or false
var t = true;
var f = false;
//undefined
var undef;//defaults to undefined
var undef = undefined;//not common, use null
//null
var nul = null;
//array
var arr = ['Hello','my','name','is','Dr.Hippo',123,null];
//object
var person = {'name':'John Smith','age':27};
//function
var fun = function(){
return 42;
}var i = 10;//String Data Type
var strSingle = 'John'; //String with single quotes
var strDouble = "Bob"; //String with double quotes
//Number Data Type
var num = 25; //Integer
var flo = 80.5; //Floating-point number
var exp = 4.25e+6; //Exponential notation, this equates to 4250000
//Boolean Data Type
var isReading = true; //Yes, I'm reading
var isSleeping = false; //No, I'm not sleeping
//Undefined Data Type
var undef; //If a value is never assigned, any output will be 'undefined'
//Null Data Type
var noValue = null; //Null meaning that it is has no value, not the same as 0 or ""
//Object Data Type
var emptyObject = {};
var person = {"name": "Clark", "surname": "Kent", "age": "36"}; //The quotes around the propety name can be omitted if the property name is a valid JS name
var car = { //Same as person but easier to read
model: "BMW X3", //Example with quotes around property name ommitted
color: "white",
doors: 5
}
//Array Data Type
var emptyArray = []; //An array can be of any data types (string, number, boolean, etc.)
var array = ["One", "Two"] //String array, note the index of the first element is 0
//Function Data Type
var func = function() { //Calling the function: func();
alert("Code excuted"); //Outputs: Code executed
}
var funcVar = function(amount) { //Calling the function: funcVar(6);
alert("Code excuted " + amount + " times"); //Outputs: Code executed 6 times (if input was 6)
}
//Typeof Operator
typeof variable; //Returns the data type of the variablefunction is(expected, value) {
return toString.call(value) === `[object ${expected}]`;
}
is('Object', []) // false
is('Array', []) // true
is('Object', {}) // truelet a = ["A", 1, true, [], [2, 'x'],{},{a:'B'}, NaN, undefined, null];
let s = a.toString();
console.log(s);//"A,1,true,,2,x,[object Object],[object Object],NaN,, "
Also in JavaScript:
- Title
- convert a string to html element in js
- Category
- JavaScript
- Title
- eyeshot javascript version
- Category
- JavaScript
- Title
- Data Change with Mutation
- Category
- JavaScript
- Title
- how to get selected row index of table in javascript
- Category
- JavaScript
- Title
- get caret index js
- Category
- JavaScript
- Title
- go to anchor jquery
- Category
- JavaScript
- Title
- Disable Multiple Form Submits with Vanilla JavaScript
- Category
- JavaScript
- Title
- get iso date javascript
- Category
- JavaScript
- Title
- autocomplete typeahead ajax
- Category
- JavaScript
- Title
- Better Array check with Array.isArray Because arrays are not true array in JavaScript, there is no simple typeof check. No problem! Use the method Array.isArray to check…
- Category
- JavaScript
- Title
- export apk react native
- Category
- JavaScript
- Title
- ISS proxy express
- Category
- JavaScript
- Title
- dockerfile for nodejs
- Category
- JavaScript
- Title
- how to add validator to formgroup
- Category
- JavaScript
- Title
- add custom marker in react-mapbox-gl
- Category
- JavaScript
- Title
- document delete element
- Category
- JavaScript
- Title
- event listener on parent not on childjavascript
- Category
- JavaScript
- Title
- allow cross origin node
- Category
- JavaScript
- Title
- check if var is array js
- Category
- JavaScript
- Title
- A cookie associated with a cross-site resource at http://placeholder.com/ was set without the `SameSite` attribute.
- Category
- JavaScript
- Title
- ajax with progress bar
- Category
- JavaScript
- Title
- create array of objects javascript
- Category
- JavaScript
- Title
- fetch a json from url python
- Category
- JavaScript
- Title
- how to make one line if in js
- Category
- JavaScript
- Title
- $ is not defined in jquery error
- Category
- JavaScript
- Title
- how to make a text editor in html
- Category
- JavaScript
- Title
- event listener in react
- Category
- JavaScript
- Title
- angular http call caching issue even after no-cache
- Category
- JavaScript
- Title
- dynamodb get all items nodejs
- Category
- JavaScript
- Title
- Javascript check if undefined
- Category
- JavaScript
- Title
- group all items with same name js
- Category
- JavaScript
- Title
- console.log in jsx
- Category
- JavaScript
- Title
- filter out arrays js
- Category
- JavaScript
- Title
- how to take value from html text box using parseint javascript
- Category
- JavaScript
- Title
- ajax
- Category
- JavaScript
- Title
- how to move div using jquery
- Category
- JavaScript
- Title
- How can I refresh a page with jQuery
- Category
- JavaScript
- Title
- javascript check if string contains substring
- Category
- JavaScript
- Title
- how to remove element from array in javascript
- Category
- JavaScript
- Title
- add variable numerically in javascript
- Category
- JavaScript
- Title
- funcao com o botao esc do teclado javascript
- Category
- JavaScript
- Title
- javascript change font color based on value
- Category
- JavaScript
- Title
- array to string javascript
- Category
- JavaScript
- Title
- javaScript Age in Dog years //write a function that takes your age and returns it to you in dog years - they say that 1 human year is equal to seven dog years function dog Years() javaScript
- Category
- JavaScript
- Title
- discord.js bot github
- Category
- JavaScript
- Title
- how to run mocha tests on asynchronous functions in script
- Category
- JavaScript
- Title
- javascript check if objects are equal
- Category
- JavaScript
- Title
- filter javascript array
- Category
- JavaScript
- Title
- ajax open a request
- Category
- JavaScript
- Title
- geolocation speed
- Category
- JavaScript
- Title
- array reverse algorithm in js
- Category
- JavaScript
- Title
- google sign in in firebase react
- Category
- JavaScript
- Title
- how to get the index of an array in javascript
- Category
- JavaScript
- Title
- cortar elemento y pegar en otro lugar jquery
- Category
- JavaScript
- Title
- function and returns node js
- Category
- JavaScript
- Title
- callback function js
- Category
- JavaScript
- Title
- capitalize all letters jquery
- Category
- JavaScript
- Title
- javascript classes
- Category
- JavaScript
- Title
- clear input field javascript
- Category
- JavaScript
- Title
- javascript ceiling
- Category
- JavaScript
- Title
- javascript array of cumulative sum
- Category
- JavaScript
- Title
- how to add ' in javascript string
- Category
- JavaScript
- Title
- convert date to string javascript
- Category
- JavaScript
- Title
- bootstrap javascript cdn
- Category
- JavaScript
- Title
- cannot use getidtoken if null
- Category
- JavaScript
- Title
- angular property binding
- Category
- JavaScript
- Title
- gitignore for angular
- Category
- JavaScript
- Title
- bootstrap 4 form validator with jquery
- Category
- JavaScript
- Title
- convert nuber into string react js
- Category
- JavaScript
- Title
- how to get array values in javascript
- Category
- JavaScript
- Title
- how to deploy react app in tomcat server
- Category
- JavaScript
- Title
- flatten an array in javascript
- Category
- JavaScript
- Title
- endpoint js
- Category
- JavaScript
- Title
- async axios call
- Category
- JavaScript
- Title
- express router file
- Category
- JavaScript
- Title
- devexpress custom column field
- Category
- JavaScript
- Title
- how to draw flower petals around circle javascript
- Category
- JavaScript
- Title
- get id of clicked element javascript
- Category
- JavaScript
- Title
- javascript add row to table
- Category
- JavaScript
- Title
- javascript check if is array
- Category
- JavaScript
- Title
- float to euro curency
- Category
- JavaScript
- Title
- javascript array methods
- Category
- JavaScript
- Title
- Cannot deserialize the current JSON array (e.g. [1,2,3]) into type
- Category
- JavaScript
- Title
- convert string with dot or comma as decimal separator to number in javascript
- Category
- JavaScript
- Title
- how to push values in array
- Category
- JavaScript
- Title
- format number thousands k javascript
- Category
- JavaScript
- Title
- get text selected option jquery
- Category
- JavaScript
- Title
- how to generate random string in javascript
- Category
- JavaScript
- Title
- import axios react
- Category
- JavaScript
- Title
- add month date now javascript
- Category
- JavaScript
- Title
- declare multiple variables javascript
- Category
- JavaScript
- Title
- delete from array javascript
- Category
- JavaScript
- Title
- How to create a nested schema in apollo graphql server
- Category
- JavaScript
- Title
- how to convert json to bootstrap treeview format
- Category
- JavaScript
- Title
- copy object javascript
- Category
- JavaScript
- Title
- console log larger
- Category
- JavaScript
- Title
- import react
- Category
- JavaScript
- Title
- dropzone add download button
- Category
- JavaScript
- Title
- how to delete a variable in js
- Category
- JavaScript
- Title
- fix your timestep javascript
- Category
- JavaScript