function(e,t){ e.DOMPurify=function(){"use strict"; var e=Object.freeze||function(e){return e}, t=e(["a","abbr","acronym","address","area","article","aside","audio","b","bdi","bdo","big","blink","blockquote","body","br","button","canvas","caption","center","cite","code","col","colgroup","content","data","datalist","dd","decorator","del","details","dfn","dir","div","dl","dt","element","em","fieldset","figcaption","figure","font","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","img","input","ins","kbd","label","legend","li","main","map","mark","marquee","menu","menuitem","meter","nav","nobr","ol","optgroup","option","output","p","pre","progress","q","rp","rt","ruby","s","samp","section","select","shadow","small","source","spacer","span","strike","strong","style","sub","summary","sup","table","tbody","td","template","textarea","tfoot","th","thead","time","tr","track","tt","u","ul","var","video","wbr"]), r=e(["svg","a","altglyph","altglyphdef","altglyphitem","animatecolor","animatemotion","animatetransform","audio","canvas","circle","clippath","defs","desc","ellipse","filter","font","g","glyph","glyphref","hkern","image","line","lineargradient","marker","mask","metadata","mpath","path","pattern","polygon","polyline","radialgradient","rect","stop","style","switch","symbol","text","textpath","title","tref","tspan","video","view","vkern"]), n=e(["feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDistantLight","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussianBlur","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence"]), o=e(["math","menclose","merror","mfenced","mfrac","mglyph","mi","mlabeledtr","mmultiscripts","mn","mo","mover","mpadded","mphantom","mroot","mrow","ms","mspace","msqrt","mstyle","msub","msup","msubsup","mtable","mtd","mtext","mtr","munder","munderover"]), i=e(["#text"]),a=Object.freeze||function(e){return e}, l=a(["accept","action","align","alt","autocomplete","background","bgcolor","border","cellpadding","cellspacing","checked","cite","class","clear","color","cols","colspan","controls","coords","crossorigin","datetime","default","dir","disabled","download","enctype","face","for","headers","height","hidden","high","href","hreflang","id","integrity","ismap","label","lang","list","loop","low","max","maxlength","media","method","min","multiple","name","noshade","novalidate","nowrap","open","optimum","pattern","placeholder","poster","preload","pubdate","radiogroup","readonly","rel","required","rev","reversed","role","rows","rowspan","spellcheck","scope","selected","shape","size","sizes","span","srclang","start","src","srcset","step","style","summary","tabindex","title","type","usemap","valign","value","width","xmlns"]), c=a(["accent-height","accumulate","additive","alignment-baseline","ascent","attributename","attributetype","azimuth","basefrequency","baseline-shift","begin","bias","by","class","clip","clip-path","clip-rule","color","color-interpolation","color-interpolation-filters","color-profile","color-rendering","cx","cy","d","dx","dy","diffuseconstant","direction","display","divisor","dur","edgemode","elevation","end","fill","fill-opacity","fill-rule","filter","filterunits","flood-color","flood-opacity","font-family","font-size","font-size-adjust","font-stretch","font-style","font-variant","font-weight","fx","fy","g1","g2","glyph-name","glyphref","gradientunits","gradienttransform","height","href","id","image-rendering","in","in2","k","k1","k2","k3","k4","kerning","keypoints","keysplines","keytimes","lang","lengthadjust","letter-spacing","kernelmatrix","kernelunitlength","lighting-color","local","marker-end","marker-mid","marker-start","markerheight","markerunits","markerwidth","maskcontentunits","maskunits","max","mask","media","method","mode","min","name","numoctaves","offset","operator","opacity","order","orient","orientation","origin","overflow","paint-order","path","pathlength","patterncontentunits","patterntransform","patternunits","points","preservealpha","preserveaspectratio","primitiveunits","r","rx","ry","radius","refx","refy","repeatcount","repeatdur","restart","result","rotate","scale","seed","shape-rendering","specularconstant","specularexponent","spreadmethod","stddeviation","stitchtiles","stop-color","stop-opacity","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke","stroke-width","style","surfacescale","tabindex","targetx","targety","transform","text-anchor","text-decoration","text-rendering","textlength","type","u1","u2","unicode","values","viewbox","visibility","version","vert-adv-y","vert-origin-x","vert-origin-y","width","word-spacing","wrap","writing-mode","xchannelselector","ychannelselector","x","x1","x2","xmlns","y","y1","y2","z","zoomandpan"]), s=a(["accent","accentunder","align","bevelled","close","columnsalign","columnlines","columnspan","denomalign","depth","dir","display","displaystyle","fence","frame","height","href","id","largeop","length","linethickness","lspace","lquote","mathbackground","mathcolor","mathsize","mathvariant","maxsize","minsize","movablelimits","notation","numalign","open","rowalign","rowlines","rowspacing","rowspan","rspace","rquote","scriptlevel","scriptminsize","scriptsizemultiplier","selection","separator","separators","stretchy","subscriptshift","supscriptshift","symmetric","voffset","width","xmlns"]), u=a(["xlink:href","xml:id","xlink:title","xml:space","xmlns:xlink"]),d=Object.hasOwnProperty,f=Object.setPrototypeOf,p=("undefined"!=typeof Reflect&&Reflect).apply;p||(p=function(e,t,r){return e.apply(t,r)});function m(e,t){f&&f(e,null);for(var r=t.length;r--;){var n=t[r];if("string"==typeof n){var o=n.toLowerCase();o!==n&&(Object.isFrozen(t)||(t[r]=o),n=o)}e[n]=!0}return e}function v(e){var t={},r=void 0;for(r in e)p(d,e,[r])&&(t[r]=e[r]);return t}var h=Object.seal||function(e){return e},y=h(/\{\{[\s\S]*|[\s\S]*\}\}/gm),g=h(/<%[\s\S]*|[\s\S]*%>/gm),b=h(/^data-[\-\w.\u00B7-\uFFFF]/),T=h(/^aria-[\-\w]+$/),A=h(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|cid|xmpp):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),x=h(/^(?:\w+script|data):/i),L=h(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205f\u3000]/g),S="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};function M(e){if(Array.isArray(e)){for(var t=0,r=Array(e.length);t<e.length;t++)r[t]=e[t];return r}return Array.from(e)}var k=("undefined"!=typeof Reflect&&Reflect).apply,w=Array.prototype.slice,E=Object.freeze,O=function(){return"undefined"==typeof window?null:window};k||(k=function(e,t,r){return e.apply(t,r)});var _=function(e,t){if("object"!==(void 0===e?"undefined":S(e))||"function"!=typeof e.createPolicy)return null;var r=null;t.currentScript&&t.currentScript.hasAttribute("data-tt-policy-suffix")&&(r=t.currentScript.getAttribute("data-tt-policy-suffix"));var n="dompurify"+(r?"#"+r:"");try{return e.createPolicy(n,{createHTML:function(e){return e}})}catch(e){return console.warn("TrustedTypes policy "+n+" could not be created."),null}};return function e(){var a=arguments.length>0&&void 0!==arguments[0]?arguments[0]:O();var d=function(t){return e(t)};d.version="1.0.11";d.removed=[];if(!a||!a.document||9!==a.document.nodeType)return d.isSupported=!1,d;var f=a.document;var p=!1;var h=!1;var N=a.document;var D=a.DocumentFragment,R=a.HTMLTemplateElement,C=a.Node,H=a.NodeFilter,F=a.NamedNodeMap,z=void 0===F?a.NamedNodeMap||a.MozNamedAttrMap:F,I=a.Text,j=a.Comment,P=a.DOMParser,U=a.TrustedTypes;if("function"==typeof R){var W=N.createElement("template");W.content&&W.content.ownerDocument&&(N=W.content.ownerDocument)}var B=_(U,f);var G=B?B.createHTML(""):"";var q=N,V=q.implementation,Y=q.createNodeIterator,K=q.getElementsByTagName,X=q.createDocumentFragment;var $=f.importNode;var J={};d.isSupported=V&&void 0!==V.createHTMLDocument&&9!==N.documentMode;var Q=y,Z=g,ee=b,te=T,re=x,ne=L;var oe=A;var ie=null;var ae=m({},[].concat(M(t),M(r),M(n),M(o),M(i)));var le=null;var ce=m({},[].concat(M(l),M(c),M(s),M(u)));var se=null;var ue=null;var de=!0;var fe=!0;var pe=!1;var me=!1;var ve=!1;var he=!1;var ye=!1;var ge=!1;var be=!1;var Te=!1;var Ae=!1;var xe=!0;var Le=!0;var Se=!1;var Me={};var ke=m({},["audio","head","math","script","style","template","svg","video"]);var we=m({},["audio","video","img","source","image"]);var Ee=null;var Oe=m({},["alt","class","for","id","label","name","pattern","placeholder","summary","title","value","style","xmlns"]);var _e=null;var Ne=N.createElement("form");var De=function(e){_e&&_e===e||(e&&"object"===(void 0===e?"undefined": S(e))||(e={}),ie="ALLOWED_TAGS"in e?m({},e.ALLOWED_TAGS):ae,le="ALLOWED_ATTR"in e?m({},e.ALLOWED_ATTR): ce,Ee="ADD_URI_SAFE_ATTR"in e?m({},e.ADD_URI_SAFE_ATTR):Oe,se="FORBID_TAGS"in e?m({},e.FORBID_TAGS):{},ue="FORBID_ATTR"in e?m({},e.FORBID_ATTR):{},Me="USE_PROFILES"in e&&e.USE_PROFILES,de=!1!==e.ALLOW_ARIA_ATTR,fe=!1!==e.ALLOW_DATA_ATTR,pe=e.ALLOW_UNKNOWN_PROTOCOLS||!1,me=e.SAFE_FOR_JQUERY||!1, ve=e.SAFE_FOR_TEMPLATES||!1,he=e.WHOLE_DOCUMENT||!1,be=e.RETURN_DOM||!1,Te=e.RETURN_DOM_FRAGMENT||!1, Ae=e.RETURN_DOM_IMPORT||!1,ge=e.FORCE_BODY||!1,xe=!1!==e.SANITIZE_DOM,Le=!1!==e.KEEP_CONTENT,Se=e.IN_PLACE||!1,oe=e.ALLOWED_URI_REGEXP||oe,ve&&(fe=!1),Te&&(be=!0),Me&&(ie=m({},[].concat(M(i))),le=[],!0===Me.html&&(m(ie,t),m(le,l)),!0===Me.svg&&(m(ie,r),m(le,c),m(le,u)),!0===Me.svgFilters&&(m(ie,n),m(le,c),m(le,u)),!0===Me.mathMl&&(m(ie,o),m(le,s),m(le,u))),e.ADD_TAGS&&(ie===ae&&(ie=v(ie)),m(ie,e.ADD_TAGS)),e.ADD_ATTR&&(le===ce&&(le=v(le)),m(le,e.ADD_ATTR)),e.ADD_URI_SAFE_ATTR&&m(Ee,e.ADD_URI_SAFE_ATTR),Le&&(ie["#text"]=!0),he&&m(ie,["html","head","body"]),ie.table&&m(ie,["tbody"]),E&&E(e),_e=e)};var Re=function(e){d.removed.push({element:e});try{e.parentNode.removeChild(e)}catch(t){e.outerHTML=G}};var Ce=function(e,t){try{d.removed.push({attribute:t.getAttributeNode(e),from:t})}catch(e){d.removed.push({attribute:null,from:t})}t.removeAttribute(e)};var He=function(e){var t=void 0,r=void 0;if(ge)e="<remove></remove>"+e;else{var n=e.match(/^[\s]+/);(r=n&&n[0])&&(e=e.slice(r.length))}if(p)try{t=(new P).parseFromString(e,"text/html")}catch(e){}if(h&&m(se,["title"]),!t||!t.documentElement){var o=t=V.createHTMLDocument(""),i=o.body;i.parentNode.removeChild(i.parentNode.firstElementChild),i.outerHTML=B?B.createHTML(e):e}return r&&t.body.insertBefore(N.createTextNode(r),t.body.childNodes[0]||null),K.call(t,he?"html":"body")[0]};d.isSupported&&(function(){try{var e=He('<svg><p><textarea><img src="</textarea><img src=x onerror=1//">');e.querySelector("svg img")&&(p=!0)}catch(e){}}(),function(){try{var e=He("<x/><title></title><img>");e.querySelector("title").innerHTML.match(/<\/title/)&&(h=!0)}catch(e){}}());var Fe=function(e){return Y.call(e.ownerDocument||e,e,H.SHOW_ELEMENT|H.SHOW_COMMENT|H.SHOW_TEXT,function(){return H.FILTER_ACCEPT},!1)};var ze=function(e){return"object"===(void 0===C?"undefined":S(C))?e instanceof C:e&&"object"===(void 0===e?"undefined":S(e))&&"number"==typeof e.nodeType&&"string"==typeof e.nodeName};var Ie=function(e,t,r){J[e]&&J[e].forEach(function(e){e.call(d,t,r,_e)})};var je=function(e){var t=void 0;if(Ie("beforeSanitizeElements",e,null),function(e){if(e instanceof I||e instanceof j)return!1;if("string"!=typeof e.nodeName||"string"!=typeof e.textContent||"function"!=typeof e.removeChild||!(e.attributes instanceof z)||"function"!=typeof e.removeAttribute||"function"!=typeof e.setAttribute)return!0;return!1}(e))return Re(e),!0;var r=e.nodeName.toLowerCase();if(Ie("uponSanitizeElement",e,{tagName:r,allowedTags:ie}),!ie[r]||se[r]){if(Le&&!ke[r]&&"function"==typeof e.insertAdjacentHTML)try{var n=e.innerHTML;e.insertAdjacentHTML("AfterEnd",B?B.createHTML(n):n)}catch(e){}return Re(e),!0}return"noscript"===r&&e.innerHTML.match(/<\/noscript/i)?(Re(e),!0):"noembed"===r&&e.innerHTML.match(/<\/noembed/i)?(Re(e),!0):(!me||e.firstElementChild||e.content&&e.content.firstElementChild||!/</g.test(e.textContent)||(d.removed.push({element:e.cloneNode()}),e.innerHTML?e.innerHTML=e.innerHTML.replace(/</g,"<"):e.innerHTML=e.textContent.replace(/</g,"<")),ve&&3===e.nodeType&&(t=(t=(t=e.textContent).replace(Q," ")).replace(Z," "),e.textContent!==t&&(d.removed.push({element:e.cloneNode()}),e.textContent=t)), Ie("afterSanitizeElements",e,null),!1)};var Pe=function(e,t,r){if(xe&&("id"===t||"name"===t)&&(r in N||r in Ne))return!1; if(fe&&ee.test(t));else if(de&&te.test(t));else{if(!le[t]||ue[t])return!1; if(Ee[t]);else if(oe.test(r.replace(ne,"")));else if("src"!==t&&"xlink:href"!==t&&"href"!==t||"script"===e||0!==r.indexOf("data:")||!we[e]) {if(pe&&!re.test(r.replace(ne,""))); else if(r)return!1}else;}return!0}; var Ue=function(e){var t=void 0,r=void 0,n=void 0,o=void 0,i=void 0;Ie("beforeSanitizeAttributes",e,null);var a=e.attributes;if(a){var l={attrName:"",attrValue:"",keepAttr:!0,allowedAttributes:le}; for(i=a.length;i--;){var c=t=a[i],s=c.name,u=c.namespaceURI;if(r=t.value.trim(),n=s.toLowerCase(),l.attrName=n,l.attrValue=r,l.keepAttr=!0,Ie("uponSanitizeAttribute",e,l),r=l.attrValue,"name"===n&&"IMG"===e.nodeName&&a.id)o=a.id,a=k(w,a,[]),Ce("id",e),Ce(s,e),a.indexOf(o)>i&&e.setAttribute("id",o.value);else{if("INPUT"===e.nodeName&&"type"===n&&"file"===r&&l.keepAttr&&(le[n]||!ue[n]))continue;"id"===s&&e.setAttribute(s,""),Ce(s,e)}if(l.keepAttr){ve&&(r=(r=r.replace(Q," ")).replace(Z," ")); var f=e.nodeName.toLowerCase();if(Pe(f,n,r))try{u?e.setAttributeNS(u,s,r):e.setAttribute(s,r),d.removed.pop()}catch(e){}}}Ie("afterSanitizeAttributes",e,null)}};var We=function e(t){var r=void 0,n=Fe(t); for(Ie("beforeSanitizeShadowDOM",t,null);r=n.nextNode();)Ie("uponSanitizeShadowNode",r,null),je(r)||(r.content instanceof D&&e(r.content),Ue(r));Ie("afterSanitizeShadowDOM",t,null)};d.sanitize=function(e,t){var r=void 0,n=void 0,o=void 0,i=void 0,l=void 0;if(e||(e="\x3c!--\x3e"),"string"!=typeof e&&!ze(e)){if("function"!=typeof e.toString)throw new TypeError("toString is not a function");if("string"!=typeof(e=e.toString()))throw new TypeError("dirty is not a string, aborting")}if(!d.isSupported){if("object"===S(a.toStaticHTML)||"function"==typeof a.toStaticHTML){if("string"==typeof e)return a.toStaticHTML(e);if(ze(e))return a.toStaticHTML(e.outerHTML)}return e}if(ye||De(t),d.removed=[],Se);else if(e instanceof C)r=He("\x3c!--\x3e"),1===(n=r.ownerDocument.importNode(e,!0)).nodeType&&"BODY"===n.nodeName?r=n:"HTML"===n.nodeName?r=n:r.appendChild(n);else{if(!be&&!ve&&!he&&-1===e.indexOf("<"))return B?B.createHTML(e):e;if(!(r=He(e)))return be?null:G}r&&ge&&Re(r.firstChild);for(var c=Fe(Se?e:r);o=c.nextNode();)3===o.nodeType&&o===i||je(o)||(o.content instanceof D&&We(o.content),Ue(o),i=o);if(i=null,Se)return e;if(be){if(Te)for(l=X.call(r.ownerDocument);r.firstChild;)l.appendChild(r.firstChild);else l=r;return Ae&&(l=$.call(f,l,!0)),l}var s=he?r.outerHTML:r.innerHTML;return ve&&(s=(s=s.replace(Q," ")).replace(Z," ")),B?B.createHTML(s):s};d.setConfig=function(e){De(e),ye=!0};d.clearConfig=function(){_e=null,ye=!1};d.isValidAttribute=function(e,t,r){_e||De({});var n=e.toLowerCase(),o=t.toLowerCase();return Pe(n,o,r)};d.addHook=function(e,t){"function"==typeof t&&(J[e]=J[e]||[],J[e].push(t))};d.removeHook=function(e){J[e]&&J[e].pop()};d.removeHooks=function(e){J[e]&&(J[e]=[])};d.removeAllHooks=function(){J={}};return d}()}()}(this);
Write, Run & Share Javascript code online using OneCompiler's JS online compiler for free. It's one of the robust, feature-rich online compilers for Javascript language. Getting started with the OneCompiler's Javascript editor is easy and fast. The editor shows sample boilerplate code when you choose language as Javascript and start coding.
Javascript(JS) is a object-oriented programming language which adhere to ECMA Script Standards. Javascript is required to design the behaviour of the web pages.
var readline = require('readline');
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: false
});
rl.on('line', function(line){
console.log("Hello, " + line);
});
Keyword | Description | Scope |
---|---|---|
var | Var is used to declare variables(old way of declaring variables) | Function or global scope |
let | let is also used to declare variables(new way) | Global or block Scope |
const | const is used to declare const values. Once the value is assigned, it can not be modified | Global or block Scope |
let greetings = `Hello ${name}`
const msg = `
hello
world!
`
An array is a collection of items or values.
let arrayName = [value1, value2,..etc];
// or
let arrayName = new Array("value1","value2",..etc);
let mobiles = ["iPhone", "Samsung", "Pixel"];
// accessing an array
console.log(mobiles[0]);
// changing an array element
mobiles[3] = "Nokia";
Arrow Functions helps developers to write code in concise way, it’s introduced in ES6.
Arrow functions can be written in multiple ways. Below are couple of ways to use arrow function but it can be written in many other ways as well.
() => expression
const numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
const squaresOfEvenNumbers = numbers.filter(ele => ele % 2 == 0)
.map(ele => ele ** 2);
console.log(squaresOfEvenNumbers);
let [firstName, lastName] = ['Foo', 'Bar']
let {firstName, lastName} = {
firstName: 'Foo',
lastName: 'Bar'
}
const {
title,
firstName,
lastName,
...rest
} = record;
//Object spread
const post = {
...options,
type: "new"
}
//array spread
const users = [
...adminUsers,
...normalUsers
]
function greetings({ name = 'Foo' } = {}) { //Defaulting name to Foo
console.log(`Hello ${name}!`);
}
greet() // Hello Foo
greet({ name: 'Bar' }) // Hi Bar
IF is used to execute a block of code based on a condition.
if(condition){
// code
}
Else part is used to execute the block of code when the condition fails.
if(condition){
// code
} else {
// code
}
Switch is used to replace nested If-Else statements.
switch(condition){
case 'value1' :
//code
[break;]
case 'value2' :
//code
[break;]
.......
default :
//code
[break;]
}
For loop is used to iterate a set of statements based on a condition.
for(Initialization; Condition; Increment/decrement){
//code
}
While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.
while (condition) {
// code
}
Do-while is also used to iterate a set of statements based on a condition. It is mostly used when you need to execute the statements atleast once.
do {
// code
} while (condition);
ES6 introduced classes along with OOPS concepts in JS. Class is similar to a function which you can think like kind of template which will get called when ever you initialize class.
class className {
constructor() { ... } //Mandatory Class method
method1() { ... }
method2() { ... }
...
}
class Mobile {
constructor(model) {
this.name = model;
}
}
mbl = new Mobile("iPhone");