Create Syntax Highlighting Code with JavaScript

Srinivas Gorla
Updated on 23-Jun-2020 12:00:35

199 Views

To create a syntax-highlighting code with JavaScript, use the prettify library. Add the following in your code to add the library for syntax highlighting −To use it, add the following to your tag −    Code comes here

JavaScript Code for Multiple Keys Pressed at Once

Arjun Thakur
Updated on 23-Jun-2020 11:59:51

671 Views

Use the keydown event in JavaScript to get to know which keys are pressed at once. The following is the script −Examplevar log = $('#log')[0],    keyPressed = []; $(document.body).keydown(function (evt) {    var li = keyPressed [evt.keyCode];    if (!li) {       li = log.appendChild(document.createElement('li'));       keyPressed [evt.keyCode] = li;    }    $(li).text(Key Down: ' + evt.keyCode);    $(li).removeClass('key-up'); }); $(document.body).keyup(function (evt) {    var li = keyPressed [evt.keyCode];    if (!li) {       li = log.appendChild(document.createElement('li'));    }    $(li).text('Key Up: ' + evt.keyCode);    $(li).addClass('key-up'); });

JavaScript Not In Operator for Checking Object Properties

Vrundesha Joshi
Updated on 23-Jun-2020 11:59:16

2K+ Views

To get only the else part, just negate, using ! the operator in JavaScript. You can try to run the following code to achieve this −var arr = {}; if (!(id in arr)) { } else { }In addition, if you want the existence of a property in an object, then use hasOwnProperty −if (!arr.hasOwnProperty(id)) { } else { }

Define Global Variable in a JavaScript Function

Sravani S
Updated on 23-Jun-2020 11:56:54

417 Views

To declare a global variable, use the var at global scope −    var myGlobalVariable;    function display() {       //    } For JavaScript function, assign the property to a window −    function display() {       window. myGlobalVariable = …;    }

Create JavaScript Data Grid for Millions of Rows

Nancy Den
Updated on 23-Jun-2020 11:51:58

313 Views

To display million of rows of data to the users in a grid, use any of the following grids −S. NoGridDescription1DataTablesAllows adding advanced interaction controls to any HTML table.2IngridAllows resizing columns, paging, sorting, row and column styling to tables.3SlickGridUses virtual rendering to allow you to work with hundreds of thousands of items.Let us see the features of SlickGrid −Easily customizableComplete keyboard navigationEasily handles hundreds of thousands of rowsQuick rendering speedColumn autosizing availablePluggable cell formatters availableAllos creating new rows

Why Does JavaScript Need to Start with 'use strict'?

Ramu Prasad
Updated on 23-Jun-2020 11:51:06

165 Views

JavaScript uses a semi-colon (;) to avoid any confusion in code, especially the beginning of a new line.ExampleYou can still use the following to avoid any chaos in the code −return {    'var':myVal } // using semi-colon; (function( $ ) {    // }

Scope Resolution Operator in C#

karthikeya Boyini
Updated on 23-Jun-2020 11:50:48

1K+ Views

The scope resolution operator in C# has a different meaning as compared with C++. In C++ the :: is used for global variables, whereas in C# it is related to namespaces.If you have a type that share an identifier in different namespace, then to identify them use the scope resolution operator.For example, to reference System.Console class, use the global namespace alias with the scope resolution operator.global::System.ConsoleExample Live Demousing myAlias = System.Collections; namespace Program {    class Demo {       static void Main() {          myAlias::Hashtable h = new myAlias::Hashtable();          h.Add("Q", "1");   ... Read More

IsFixedSize Property of ArrayList Class in C#

Samual Sam
Updated on 23-Jun-2020 11:48:55

129 Views

The IsFixedSize property of ArrayList class is used to get a value indicating whether the ArrayList has a fixed size.The following is an example stating the usage of isFixedSize property.Example Live Demousing System; using System.Collections; class Demo {    public static void Main() {       ArrayList arrList = new ArrayList();       Console.WriteLine("Adding some numbers:");       arrList.Add(45);       arrList.Add(78);       Console.WriteLine(arrList.Count);       Console.WriteLine("myArrayList.IsFixedSize = " + arrList.IsFixedSize);    } }OutputAdding some numbers: 2 myArrayList.IsFixedSize = FalseAbove we have added an array list.ArrayList arrList = new ArrayList();Then we have checked whether ... Read More

IsReadOnly Property of ArrayList Class in C#

karthikeya Boyini
Updated on 23-Jun-2020 11:48:23

157 Views

The IsReadOnly property of ArrayList class is useful to get a value indicating whether the ArrayList is read-only.Firstly, we have the following ArrayList.ArrayList arrList = new ArrayList();Then we have checked using the IsReadOnly Property.Console.WriteLine("myArrayList.IsReadOnly = " + arrList.IsReadOnly);The following is an example showing how to work with IsReadOnly property in ArrayList class.Example Live Demousing System; using System.Collections; class Demo {    public static void Main() {       ArrayList arrList = new ArrayList();       Console.WriteLine("myArrayList.IsReadOnly = " + arrList.IsReadOnly);    } }OutputmyArrayList.IsReadOnly = False

Check Whether a List is Empty or Not in C#

Chandu yadav
Updated on 23-Jun-2020 11:48:02

10K+ Views

Use lists in C# to store elements and fetch it. Let us see an example.Example Live Demousing System; using System.Collections.Generic; public class Demo {    public static void Main(string[] args) {       var subjects = new List();       subjects.Add("Maths");       subjects.Add("Java");       subjects.Add("English");       subjects.Add("Science");       subjects.Add("Physics");       subjects.Add("Chemistry");       foreach (var sub in subjects) {          Console.WriteLine(sub);       }    } }OutputMaths Java English Science Physics ChemistryNow to check whether a list is empty or not, use the Count ... Read More

Advertisements