Skip to content

navya-javascript-variables-and-datatypes-assignments#541

Open
navya-1417 wants to merge 1 commit intoaptyInc:mainfrom
navya-1417:javascript-variables-and-datatypes-assignments
Open

navya-javascript-variables-and-datatypes-assignments#541
navya-1417 wants to merge 1 commit intoaptyInc:mainfrom
navya-1417:javascript-variables-and-datatypes-assignments

Conversation

@navya-1417
Copy link
Copy Markdown

@navya-1417 navya-1417 commented Nov 10, 2025

Terms and Conditions

  • I Accept losing points if my PR does not follow the best practices mentioned below, which will impact my overall performance in training

HTML Best Practices

  • File Naming Convention:

  • Follow consistent and descriptive naming (e.g., dashboard.html, user-profile.html).

  • Use lowercase letters and hyphens instead of spaces.

  • Page Title:

  • Ensure the <title> tag is descriptive and aligns with the page content.

  • Include meaningful keywords for SEO if applicable.

  • Semantic Markup:

  • Use appropriate tags like <header>, <footer>, <section>, <article> for better readability and accessibility.

  • Accessibility Standards:

  • Ensure the use of alt attributes for images and proper labels for form elements.

  • Use ARIA roles where necessary.

  • Validation:

  • Ensure the code passes HTML validation tools without errors or warnings.

  • Structure and Indentation:

  • Maintain consistent indentation and proper nesting of tags.

  • Attributes:

  • Ensure all required attributes (e.g., src, href, type, etc.) are correctly used and not left empty.

CSS Best Practices

  • File Organization:

  • Use modular CSS files if applicable (e.g., base.css, layout.css, theme.css).

  • Avoid inline styles unless absolutely necessary.

  • Naming Conventions:

  • Use meaningful class names following BEM or other conventions (e.g., block__element--modifier).

  • Code Reusability:

  • Avoid duplicate code; use classes or mixins for shared styles.

  • Responsive Design:

  • Ensure proper usage of media queries for mobile, tablet, and desktop views.

  • Performance Optimization:

  • Minimize the use of unnecessary CSS selectors.

  • Avoid overly specific selectors and ensure selectors are not overly deep (e.g., avoid #id .class1 .class2 p).

  • Consistency:

  • Follow consistent spacing, indentation, and use of units (rem/em vs. px).

  • Maintain a single coding style (e.g., always use double or single quotes consistently).

Javascript Best Practices

  • File Organization:

  • Ensure scripts are modular and logically separated into files if needed.

  • Avoid mixing inline JavaScript with HTML.

  • Logic Optimization:

  • Check for redundancy and ensure the code is optimized for performance.

  • Avoid unnecessary API calls or DOM manipulations.

  • Solution Approach:

  • Confirm that the code solves the given problem efficiently.

  • Consider scalability for future enhancements.

  • Readability:

  • Use clear variable and function names.

  • Add comments for complex logic or algorithms.

  • Error Handling:

  • Ensure proper error handling for API calls or user input validation.

  • Code Quality:

  • Check for potential bugs (e.g., missing await, mishandling of null/undefined values).

  • Avoid unnecessary console.log statements in production code.

  • Security:

  • Avoid hardcoding sensitive data.

  • Sanitize user input to prevent XSS and other vulnerabilities.

  • Best Practices:

  • Use const and let instead of var.

  • Follow ES6+ standards where applicable.

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @navya-1417, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a comprehensive set of six JavaScript assignments designed to teach fundamental concepts. It covers various methods of JavaScript execution, the distinctions between var, let, and const for variable handling, and an in-depth look at JavaScript's core data types. The changes also include practical demonstrations of both explicit type conversion and implicit type coercion, alongside the modern usage of template literals for string manipulation. The assignments are structured for clear understanding and are accessible via a single, organized HTML entry point.

Highlights

  • JavaScript Execution Methods: Introduced and demonstrated three ways to execute JavaScript: inline, internal, and external scripting, showcasing their integration within HTML.
  • Variable Declaration Keywords: Explored the differences between var, let, and const for variable declaration, illustrating their re-declaration and re-assignment behaviors with practical examples and error handling.
  • JavaScript Data Types: Provided examples and explanations for various JavaScript data types, including String, Number, Boolean, Undefined, Null, Symbol, and Object, along with how to determine their types using typeof.
  • Explicit Type Conversion: Demonstrated explicit type conversion using built-in functions like Number(), String(), and Boolean() to convert values between different data types.
  • Implicit Type Coercion: Illustrated how JavaScript performs implicit type coercion during operations, particularly with the + operator, when different data types are involved.
  • Template Literals: Showcased the use of template literals (backticks) for enhanced string formatting, including variable interpolation and multi-line strings.
  • Centralized Assignment Access: Created a main index.html file that serves as a dashboard, allowing easy navigation and viewing of all six assignments through embedded iframes within collapsible sections.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds several small assignments demonstrating JavaScript variables, data types, and related concepts. The code generally achieves its purpose, but there are several areas for improvement. I've identified some conceptual errors in the demonstration of let and const scoping, as well as inefficient DOM manipulation patterns that cause performance issues. Additionally, some of the submitted code contradicts the best practices checklist in the pull request description. My review includes suggestions to correct these issues and improve code quality and performance.

Comment on lines +10 to +16
output.innerHTML += `Number + Number: ${num + num}<br>`;
output.innerHTML += `String + Number: ${str + num}<br>`;
output.innerHTML += `Number + Boolean: ${num + bool}<br>`;
output.innerHTML += `Null + Number: ${nul + num}<br>`;
output.innerHTML += `Undefined + Number: ${undef + num}<br>`;
output.innerHTML += `Number + Object: ${num + obj}<br>`;
output.innerHTML += `Object + String: ${obj + str}<br>`; No newline at end of file
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Repeatedly appending to innerHTML is inefficient as it causes the browser to re-parse and re-render the DOM on each call. It's more performant to build the full HTML string first and then update the DOM with a single innerHTML assignment.

Comment on lines +11 to +29
output.innerHTML += "<h3>To Number:</h3>";
output.innerHTML += `String : ${Number(str)}<br>`;
output.innerHTML += `Boolean : ${Number(bool)}<br>`;
output.innerHTML += `Null : ${Number(nul)}<br>`;
output.innerHTML += `Undefined : ${Number(undef)}<br>`;

output.innerHTML += "<h3>To String:</h3>";
output.innerHTML += `Number : ${String(num)}<br>`;
output.innerHTML += `Boolean : ${String(bool)}<br>`;
output.innerHTML += `Undefined : ${String(undef)}<br>`;
output.innerHTML += `Null : ${String(nul)}<br>`;
output.innerHTML += `Symbol : ${sym.toString()}<br>`;
output.innerHTML += `Object : ${String(obj)}<br>`;

output.innerHTML += "<h3>To Boolean:</h3>";
output.innerHTML += `Number : ${Boolean(num)}<br>`;
output.innerHTML += `Undefined : ${Boolean(undef)}<br>`;
output.innerHTML += `Null : ${Boolean(nul)}<br>`;
output.innerHTML += `Object : ${Boolean(obj)}<br>`; No newline at end of file
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Repeatedly modifying innerHTML with += is inefficient. Each time innerHTML is set, the browser has to re-parse and re-render the content, which can lead to poor performance. It's much better to build the entire HTML string in a variable first and then set innerHTML only once.

Suggested change
output.innerHTML += "<h3>To Number:</h3>";
output.innerHTML += `String : ${Number(str)}<br>`;
output.innerHTML += `Boolean : ${Number(bool)}<br>`;
output.innerHTML += `Null : ${Number(nul)}<br>`;
output.innerHTML += `Undefined : ${Number(undef)}<br>`;
output.innerHTML += "<h3>To String:</h3>";
output.innerHTML += `Number : ${String(num)}<br>`;
output.innerHTML += `Boolean : ${String(bool)}<br>`;
output.innerHTML += `Undefined : ${String(undef)}<br>`;
output.innerHTML += `Null : ${String(nul)}<br>`;
output.innerHTML += `Symbol : ${sym.toString()}<br>`;
output.innerHTML += `Object : ${String(obj)}<br>`;
output.innerHTML += "<h3>To Boolean:</h3>";
output.innerHTML += `Number : ${Boolean(num)}<br>`;
output.innerHTML += `Undefined : ${Boolean(undef)}<br>`;
output.innerHTML += `Null : ${Boolean(nul)}<br>`;
output.innerHTML += `Object : ${Boolean(obj)}<br>`;
const content = [
"<h3>To Number:</h3>",
`String : ${Number(str)}<br>`,
`Boolean : ${Number(bool)}<br>`,
`Null : ${Number(nul)}<br>`,
`Undefined : ${Number(undef)}<br>`,
"<h3>To String:</h3>",
`Number : ${String(num)}<br>`,
`Boolean : ${String(bool)}<br>`,
`Undefined : ${String(undef)}<br>`,
`Null : ${String(nul)}<br>`,
`Symbol : ${sym.toString()}<br>`,
`Object : ${String(obj)}<br>`,
"<h3>To Boolean:</h3>",
`Number : ${Boolean(num)}<br>`,
`Undefined : ${Boolean(undef)}<br>`,
`Null : ${Boolean(nul)}<br>`,
`Object : ${Boolean(obj)}<br>`
];
output.innerHTML = content.join('');


<body>
<!-- Inline Javascript -->
<button onclick="alert('Inline Javascript')">Click Me</button>
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Using an inline onclick attribute mixes JavaScript logic with HTML structure. This is against the best practice 'Avoid mixing inline JavaScript with HTML' that you've agreed to in the pull request description. While this might be for demonstration purposes in this assignment, for production code, it's better to separate concerns by attaching event listeners in a script file. This improves maintainability and readability.

Comment on lines +11 to +12
output.innerHTML += `Hi, my name is ${name} and I am ${age} years old. It's ${boolean} that I live in ${obj.location}.<br><br>`;
output.innerHTML += `My employee id is still ${undef}. My bank balance is ${nul}.`; No newline at end of file
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Repeatedly appending to innerHTML causes performance issues due to multiple DOM updates. It's better to combine the strings and set innerHTML only once.

Suggested change
output.innerHTML += `Hi, my name is ${name} and I am ${age} years old. It's ${boolean} that I live in ${obj.location}.<br><br>`;
output.innerHTML += `My employee id is still ${undef}. My bank balance is ${nul}.`;
output.innerHTML = `Hi, my name is ${name} and I am ${age} years old. It's ${boolean} that I live in ${obj.location}.<br><br>My employee id is still ${undef}. My bank balance is ${nul}.`;

Comment on lines +28 to +33
try {
const c = 20;
result += "const c re-declared: " + c + "<br>";
} catch (err) {
result += "const c re-declared: Error : " + err.message + "<br>";
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Similar to the let example, this try...catch block does not correctly demonstrate that const cannot be redeclared. The const c = 20; is in a new block scope and is a valid declaration of a new, separate constant that shadows the outer one. It will not throw an error.

document.addEventListener("DOMContentLoaded", () => {
const btn = document.querySelector("button");
btn.addEventListener("click", () => {
alert("Internal Javscript");
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

There is a typo in the alert message. "Javscript" should be "Javascript".

Suggested change
alert("Internal Javscript");
alert("Internal Javascript");


let name = "Jack";
let age = 22;
let boolean = true;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The variable name boolean is very generic and can be confused with the Boolean primitive type wrapper object. It's better to use a more descriptive name that reflects what the variable represents, for example, isStudent or hasLicense.

Suggested change
let boolean = true;
let isStudent = true;

let boolean = true;
let undef;
let nul = null;
let sym = Symbol("id");
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The variable sym is declared but its value is never used. Unused variables can make code harder to read and maintain. It should be removed if it's not needed.

Comment on lines +1 to +32
let result = "";

// String
let str = "Hello";
result += "String Value: " + str + " — Type: " + typeof str + "<br>";

// Number
let num = 100;
result += "Number Value: " + num + " — Type: " + typeof num + "<br>";

// Boolean
let isTrue = true;
result += "Boolean Value: " + isTrue + " — Type: " + typeof isTrue + "<br>";

// Undefined
let undef;
result += "Undefined Value: " + undef + " — Type: " + typeof undef + "<br>";

// Null
let nul = null;
result += "Null Value: " + nul + " — Type: " + typeof nul + "<br>";

// Symbol
let sym = Symbol("id");
result += "Symbol Value: " + sym.toString() + " — Type: " + typeof sym + "<br>";

// Object
let obj = { name: "John" };
result += "Object Value: " + JSON.stringify(obj) + " — Type: " + typeof obj + "<br>";

// Display on page
document.getElementById("resultBox").innerHTML = result;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Building a string with repeated += concatenation can be inefficient. A more performant approach is to add string fragments to an array and then use array.join('') at the end to create the final string. This avoids creating many intermediate strings and is generally better for performance.

<body>
<details>
<summary>Assignment 1</summary>
<iframe src="./assignment-1/index.html" frameborder="0" width="100%"></iframe>
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The frameborder attribute is obsolete in HTML5. For styling, you should use CSS instead. You can achieve the same result by applying border: none; to the iframe element via a style attribute or a CSS stylesheet. This helps separate content structure (HTML) from presentation (CSS).

Suggested change
<iframe src="./assignment-1/index.html" frameborder="0" width="100%"></iframe>
<iframe src="./assignment-1/index.html" style="border:0; width:100%"></iframe>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant