Showing posts with label JavaScript. Show all posts
Showing posts with label JavaScript. Show all posts

22 July 2021

Exponent operator in javascript

const data = 2 ** 4;
//same as :Math.pow(2,4);
console.log(data);

Output:

16           

Github link : https://github.com/adi501/JavaScriptExamples.git

 

Multiline string example in Javascript

console.log(`
this is a
multiline string
example`);

Output:

this is a 

multiline string 

example           

Github link : https://github.com/adi501/JavaScriptExamples.git



Default parameters in javascript

function print(a = 100) {
console.log(a);
}
print();
print(200);

Output:

100

200            

Github link : https://github.com/adi501/JavaScriptExamples.git






Arrow function in javascript

const sum = (a, b) => a + b;
console.log(sum(2, 5));

Output: 7

Github link : https://github.com/adi501/JavaScriptExamples.git





 

17 February 2021

const example in javascript

   const : The const statement is used to declares a variable in JavaScript. Let introduced from ES2015.

 JavaScript Code:

const  myName='Adi';

console.log(myName);


myName='JC';  //error

console.log(myName);

Output:

"Adi"
//error

let example in javascript

  let: The let statement is used to declares a variable in JavaScript. Let introduced from ES2015.

 JavaScript Code:

let myName='Adi';

console.log(myName);


myName='JC';

console.log(myName);

Output:

"Adi"
"JC"

var example in javascript

Var: The var statement is used to declares a variable in JavaScript. 

 JavaScript Code:

var myName='Adi';

console.log(myName);


myName='JC';

console.log(myName);

Output:

"Adi"
"JC"

11 January 2020

CSS Styling with JavaScript Object in React

  • Create Components folder under src folder
  • Add CSSJavaScriptObject.js file and add below Code
import React, { Component } from "react";

class CSSJavaScriptObject extends Component {
render() {
const mystyle = {
color: "white",
backgroundColor: "DodgerBlue",
padding: "10px",
fontFamily: "Arial"
};
return (
<div>
CSS with JavaScript Object
<h1 style={mystyle}>Style!</h1>
</div>
);
}
}
export default CSSJavaScriptObject;
  • Open index.js file and update code as below
import React from "react";
import ReactDOM from "react-dom";
import CSSJavaScriptObject from "./component/CSSJavaScriptObject";

import "./styles.css";

function App() {
return (
<div className="App">
<CSSJavaScriptObject />
</div>
);
}

const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);

Output:


5 May 2014

Dropdown events in javascript



  1.  onChange – Occurs after a value is selected from the dropdown.
  2.  onFocus – Occurs after the dropdown gains focus. It triggers the JavaScript event before the dropdown is opened.
  3. onBlur – Occurs after a value is selected from the dropdown and the focus is removed from it.
  4. onKeyDown – Occurs after a keyboard key is released when the dropdown is opened or when the dropdown has the focus.
  5. onKeyDown – Occurs after a keyboard key is pressed when the dropdown is opened or when the dropdown has the focus.
  6. onClick – Occurs after a dropdown is clicked.
  7. onMouseOver – Occurs after the dropdown is hovered with the mouse cursor.
  8. onMouseDown – Occurs after the dropdown is clicked. Works similar to the onClick event but it triggers the JavaScript event before the dropdown values are expanded.
  9.  onMouseUp – Occurs after the dropdown is clicked and the click button is released.

Textbox events in javascript

  1. OnBlur – occurs when TextBox control loses focus;
  2. OnChange – occurs when text in the TextBox control is changed;
  3. OnFocus – occurs when TextBox control gain focus;
  4. OnKeyDown – occurs when you press a keyboard key in the TextBox control;
  5. OnKeyPressed – occurs when you press or hold down a keyboard key in the TextBox control;
  6. OnKeyUp – occurs when you release the keyboard key pressed before in the TextBox control;
  7. OnClick – occurs when you click on the TextBox control;

3 April 2014

Setting focus to textbox control using JavaScript

   <script language="javascript">
        document.getElementById("TextboxControlName").focus();
    </script>

get value from dropdown (select) control in java script



alert(document.getElementById('dropdown1').value);

get value from a textbox in java script

 alert(document.getElementById('txtbox1').value);

What are the differences between scripting languages and programming languages?

The primary difference between a "programming language" (C, C++, VB etc.) and a "scripting language" (PHP, ASP, JSP, JavaScript, VBScript)is that code written in a programming language needs to be compiled before it is run. Once it is compiled, it can be run any number of times. 

Scripting languages, on the other hand, are interpreted at run-time. This means that every time you want to run the program, a separate program needs to read the code, interpret it, and then follow the instructions in the code. Compiled code has already been interpreted into machine language, so it is will typically execute faster because the conversion into machine language has already been done. 

Markup languages (HTML, XML) are somewhat different from both of the others. A markup language is simply a set of tags that are used to "mark up" text documents so that sections of text can be logically arranged and labeled. These documents can be viewed as plain text, or, more commonly, are viewed through a browser. The browser parses the document, looking for markup tags, and it then arranges the text and/or formats it according to the values in the tags.