Functions
A JavaScript function is a block of code designed to perform a particular task. It is executed when invoked or called. Instead of writing the same piece of code again and again you can put it in a function and invoke the function when required. JavaScript function can be created using the functions keyword. Some of the functions in JavaScript are:
Function | Description |
parseInt() | Parses an argument passed to it and returns an integral number. |
parseFloat() | Parses the argument and returns a floating-point number. |
isNaN() | Determines if a given value is Not a Number. |
Number() | Returns an argument after converting it to number. |
eval() | Used for evaluating JavaScript programs presented as strings. |
prompt() | Creates a dialogue box for taking input from the user. |
encodeURI() | Encodes a URI into a UTF-8 encoding scheme. |
match() | Used to search a string for a match against regular expression. |
// JS parseInt function
const num1 = parseInt("3.14");
console.log('Using parseInt("3.14") = ' + num1);
// JS parsefloat function
// It returns floating point Number until
// it encounters Not a Number character
const num2 = parseFloat("2018.12@w3wiki");
console.log('parseFloat("2018@w3wiki") = ' + num2);
// JS isNAN function
console.log(isNaN(12));
// JS number() function
const num3 = Number(true);
console.log("Value of 'true': " + num3);
// JS eval() function
function evalfn() {
const a = 4;
const b = 4;
const value = eval(new String(a * b));
console.log(value);
}
evalfn();
// JS encode URI function
const url = "https://www.google.com/search?q=geeks for geeks";
const encodedURL = encodeURI(url);
console.log(encodedURL);
JavaScript Cheat Sheet – A Basic Guide to JavaScript
JavaScript is a lightweight, open, and cross-platform programming language. It is omnipresent in modern development and is used by programmers across the world to create dynamic and interactive web content like applications and browsers. It is one of the core technologies of the World Wide Web, alongside HTML and CSS, and the powerhouse behind the rapidly evolving Internet by helping create beautiful and crazy-fast websites.
This article provides an in-depth JavaScript Cheat Sheet, a must-have for every web developer.